Lightweight ComPDF document parsing and extraction SDK
Project description
DocSlight
Lightweight Python SDK & CLI for document parsing and structured extraction
What is DocSlight?
A lightweight Python library that turns PDFs, images, and Office documents into clean Markdown or structured JSON — with one line of code. Works with ComPDF Cloud (recommended) or fully offline with local parsers.
from docslight import DocSlight
client = DocSlight(api_key="your-api-key")
result = client.parse("invoice.pdf")
print(result.to_markdown())
Quick Start
pip install docslight
Parse any document:
docslight parse invoice.pdf --output invoice.md
docslight parse invoice.pdf --format zip --output invoice.zip
Extract specific fields:
docslight extract invoice.pdf --fields invoice_number,total_amount
Launch the local Web UI workbench:
pip install "docslight[web]"
docslight web
# Open http://127.0.0.1:8000
# Or run the same Web UI directly as a module
python -m docslight.web_app --host 0.0.0.0 --port 8000 --debug
Features
- Dual mode — ComPDF Cloud for production-grade results, or local CPU parsing for offline evaluation
- Parse → Markdown — Convert PDF, DOCX, PPTX, XLSX, and images (PNG, JPG, TIFF, BMP, WebP) to clean Markdown
- Extract → JSON — Pull structured data by field list, JSON Schema, or structured template (key-value + table extraction)
- CLI first — Full-featured command-line interface, script-friendly
- Web UI — Local Flask workbench with drag-and-drop, live preview with bbox highlights, and a Fields Builder UI
- Batch processing —
parse_batch()/extract_batch()for multiple files - Local LLM extraction — Ollama or any OpenAI-compatible provider for offline extraction
- Document types — Classify and route documents by type for cloud extraction
- Error-safe — Typed result objects, structured error hierarchy, no credential leaks
Install
| Scenario | Command |
|---|---|
| Core SDK & CLI | pip install docslight |
| + Local parsing (OCR, Office) | pip install "docslight[local]" |
| + Local LLM extraction | pip install "docslight[local,local-llm]" |
| + Web UI workbench | pip install "docslight[web]" |
Local CPU parsing is experimental. Validate accuracy and latency on your own documents before production use.
SDK Usage
Cloud — Parse
from docslight import DocSlight
client = DocSlight(mode="cloud", api_key="your-api-key")
result = client.parse("invoice.pdf")
print(result.to_markdown()) # Clean markdown
print(result.to_json()) # Full result with pages + metadata
Cloud — Extract
result = client.extract(
"invoice.pdf",
fields=["invoice_number", "invoice_date", "total_amount"],
)
print(result.to_json())
With a JSON Schema:
schema = {
"type": "object",
"properties": {
"invoice_number": {"type": "string"},
"total_amount": {"type": "number"},
},
"required": ["invoice_number"],
}
result = client.extract("invoice.pdf", schema=schema)
With document type classification:
result = client.extract(
"invoice.pdf",
fields=["invoice_number"],
document_types=["invoice"],
)
Local — Parse (Offline)
client = DocSlight(mode="local")
result = client.parse("invoice.pdf")
print(result.to_markdown())
Local — Extract with Ollama
client = DocSlight(
mode="local",
local_llm={"provider": "ollama", "model": "llama3.1"},
)
result = client.extract(
"invoice.pdf",
fields=["invoice_number", "invoice_date"],
)
Local — Extract with OpenAI-Compatible API
client = DocSlight(
mode="local",
local_llm={
"provider": "openai-compatible",
"base_url": "https://your-endpoint/v1",
"model": "your-model",
"api_key": "your-api-key",
"extra_body": {"enable_thinking": False}, # e.g., DashScope qwen3
},
)
Batch Processing
results = client.parse_batch(["doc1.pdf", "doc2.pdf", "doc3.pdf"])
for r in results:[release.ps1](scripts/release.ps1)
print(r.to_markdown()[:200])
CLI Usage
# Parse
docslight parse invoice.pdf --mode cloud -o invoice.zip
docslight parse invoice.pdf --mode cloud --format zip -o invoice.zip
docslight parse invoice.pdf --mode local -o invoice.zip
# Extract
docslight extract invoice.pdf --mode cloud --fields invoice_number,total_amount
docslight extract invoice.pdf --mode local --fields invoice_number --local-llm-provider ollama --local-llm-model llama3.1
docslight extract "D:\pdf\invoice\1.pdf" --mode local --fields invoice_number --local-llm-provider ollama
# Extract with schema
docslight extract invoice.pdf --schema schema.json
# Web UI
docslight web --host 127.0.0.1 --port 8000
Web UI Workbench
DocSlight Workbench is a local Flask app for visual document processing.
pip install "docslight[web]"
docslight web
python -m docslight.web_app
- Parse & Extract tabs — Switch between parsing and extraction workflows
- Drag-and-drop upload — PDF, images, DOCX, PPTX, XLSX
- Live preview — PDF page rendering with bbox highlight overlays
- Fields Builder — Structured UI for building key-value and table extraction templates
- Download results — One-click download of Markdown or JSON output
Environment Variables
| Variable | Description |
|---|---|
DOCSLIGHT_API_KEY |
API key for cloud mode |
DOCSLIGHT_MODE |
Processing mode: cloud or local (default: cloud) |
Supported Inputs
| Mode | Formats |
|---|---|
| Cloud | PDF, images (PNG/JPG/TIFF/BMP/WebP), DOCX, PPTX, XLSX, and more via ComPDF Cloud API |
| Local | PDF, images (PNG/JPG/TIFF/BMP/WebP), DOCX, PPTX, XLSX |
Legacy Office formats (
.doc,.ppt,.xls) must be converted to DOCX/PPTX/XLSX for local processing.
Development
pip install -e ".[dev]"
ruff check .
mypy docslight
pytest
python -m build
License
MIT License. See LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docslight-0.1.2.tar.gz.
File metadata
- Download URL: docslight-0.1.2.tar.gz
- Upload date:
- Size: 58.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a78a320b11b658dd68fc26344824928655ac01c9e37954649be94da2f1b96139
|
|
| MD5 |
31665903f6a6379f8648a40f409e9aa0
|
|
| BLAKE2b-256 |
201e93c0b01fa76189967a613d46c6289336b81c066caa100e449b71e8cb173b
|
File details
Details for the file docslight-0.1.2-py3-none-any.whl.
File metadata
- Download URL: docslight-0.1.2-py3-none-any.whl
- Upload date:
- Size: 68.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dfb987c5bb613dd1dc09e6697bf8b5b05903bf367688605f0f8703e393148b0
|
|
| MD5 |
91a857e97c32e9de38e926fd8c2f72c9
|
|
| BLAKE2b-256 |
e42fcbca747c930fccab2b402b083480e218b9d8d196249756549ef38c81b459
|