xberg
它能做什么
这项技能帮助开发者使用 Xberg 库,在 Python、Node.js、Rust 或命令行中读取文档。适合构建需要读取文档内部文字或数据的工具的人。
适用场景
- ✓当你在编写代码,需要从 PDF、Word 文件或电子邮件中提取文字时。
- ✓当你需要对扫描页面或图片进行 OCR 时。
- ✓当你希望使用相同的设置一次批量处理多个文档时。
技能链接
https://github.com/xberg-io/xberg/blob/main/plugin/.ai-rulez/skills/xberg/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请编写一个 Python 脚本,从我所有的 PDF 发票中提取文字和表格。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会为你所用的语言安装 Xberg 包,选择你需要的选项(例如 OCR 或切分),并编写代码,从每个文档中返回文字、表格和元数据。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Xberg Document Extraction
Xberg is a document intelligence library with a Rust core and bindings for Python, TypeScript/Node.js, Ruby, PHP, Go, Java, C#, Elixir, WebAssembly, Dart, Kotlin Android, Swift, Zig, and C. It extracts text, tables, metadata, and images from 107 formats across 140 unique file extensions and accepts 53 compatibility MIME aliases, including PDF, Office documents, images, HTML, email, archives, and academic formats.
Use this skill when writing code that:
- Extracts text or metadata from documents
- Performs OCR on scanned documents or images
- Batch-processes multiple files
- Configures extraction options (output format, chunking, OCR, language detection)
- Implements custom plugins (post-processors, validators, OCR backends)
If the
xbergMCP server is registered in this session, prefer its tools over shelling out to the CLI — they expose the same extraction surface with structured arguments and results.
Installation
Python
pip install xberg
Node.js
npm install @xberg-io/xberg
Rust
cargo add xberg
# Cargo.toml
[dependencies]
xberg = { version = "1.1.0", features = ["full"] }
tokio = { version = "1", features = ["full"] }
# feature flags: pdf, ocr, chunking, embeddings, language-detection, keywords, api, mcp
# (or "formats" / "full" aggregates); tokio-runtime is on by default
CLI
brew install xberg-io/tap/xberg
# or run without a persistent install (the CLI proxy package self-installs the binary):
npx @xberg-io/xberg-cli@1.3.10 --help
uvx --from xberg-cli==1.3.8 xberg --help
# or download a prebuilt binary from the latest GitHub release:
# https://github.com/xberg-io/xberg/releases/latest
# or build from source:
cargo install xberg-cli
Quick Start
The library entry points are extract(input, config) and extract_batch(inputs, config). Both return an ExtractionResult envelope — the extracted document(s) live in result.results, and per-document data (content, tables, metadata, …) is on each result.results[i]. Python and Node are async-only.
Python
import asyncio
from xberg import ExtractInput, extract, ExtractionConfig
async def main() -> None:
result = await extract(ExtractInput(uri="document.pdf"), ExtractionConfig())
doc = result.results[0]
print(doc.content) # extracted text
print(doc.metadata) # document metadata
print(doc.tables) # extracted tables
asyncio.run(main())
Node.js
import { extract } from "@xberg-io/xberg";
const output = await extract({ kind: "uri", uri: "document.pdf" });
const doc = output.results[0];
console.log(doc.content);
console.log(doc.metadata);
console.log(doc.tables);
Rust
use xberg::{extract, ExtractInput, ExtractionConfig};
#[tokio::main]
async fn main() -> xberg::Result<()> {
let output = extract(ExtractInput::from_uri("document.pdf"), &ExtractionConfig::default()).await?;
println!("{}", output.results[0].content);
Ok(())
}
CLI
xberg extract document.pdf
xberg extract document.pdf --format json
xberg extract document.pdf --content-format markdown
Configuration
All languages use the same configuration structure with language-appropriate naming conventions.
Python (snake_case)
from xberg import (
ExtractInput, extract,
ExtractionConfig, OcrConfig, TesseractConfig, PdfConfig, ChunkingConfig, OutputFormat,
)
config = ExtractionConfig(
ocr=OcrConfig(
backend="tesseract",
language=["eng"],
tesseract_config=TesseractConfig(psm=6, enable_table_detection=True),
),
pdf_options=PdfConfig(passwords=["secret123"]),
chunking=ChunkingConfig(max_characters=1000, overlap=200),
output_format=OutputFormat("markdown"),
)
result = await extract(ExtractInput(uri="document.pdf"), config)
Node.js (camelCase)
import { extract, type ExtractionConfig } from "@xberg-io/xberg";
const config: ExtractionConfig = {
ocr: { backend: "tesseract", language: ["eng"] },
pdfOptions: { passwords: ["secret123"] },
chunking: { maxCharacters: 1000, overlap: 200 },
outputFormat: "markdown",
};
const output = await extract({ kind: "uri", uri: "document.pdf" }, config);
Rust (snake_case)
use xberg::{extract, ExtractInput, ExtractionConfig, OcrConfig, ChunkingConfig, OutputFormat};
let config = ExtractionConfig {
ocr: Some
常见问题
它支持哪些语言?
这项技能涵盖 Python、Node.js 和 TypeScript、Rust 以及命令行,并列出了其他语言的绑定。
它能读取扫描文档吗?
可以。它可以对扫描页面和图片进行 OCR,并在 PDF 没有可用文字时强制进行 OCR。
它需要单独的服务器吗?
不需要。这项技能直接使用该库,不过当 Xberg 服务器已连接时,它会优先使用 Xberg 工具。
详情
作者的原始描述
Extract text, tables, metadata, and images from 107 document formats (PDF, Office, images, HTML, email, archives, academic) using Xberg. Use when writing code that calls Xberg APIs in Python, Node.js/TypeScript, Rust, or CLI. Covers installation, extraction (sync/async), configuration (OCR, chunking, output format), batch processing, error handling, and plugins.
repo: xberg-io/xberg
热度
- GitHub 星标
- 9.5k
- 排名
- #12274
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
xberg-batch-extraction
9.5k帮你的智能体使用 Xberg 一次处理大量文档,共用一组选项,限制并行工作量,并让失败的文件不会中断整个任务。
xberg-chunking
9.5k帮你的智能体把长文档文字切分为较小的片段,用于 AI 提示或搜索索引,可设置大小并可选择重叠部分。
xberg-extracting-keywords
9.5k帮你的智能体使用 Xberg 的关键词设置,从文档中提取主要关键词或关键短语,并检测文档语言。
xberg-extracting-tables
9.5k帮你的智能体从 PDF、电子表格和图片中提取表格,并以 Markdown 或结构化数据的形式保持行和列的完整。