Skip to main content

Lightweight ComPDF document parsing and extraction SDK

Project description

DocSlight

Lightweight Python SDK & CLI for document parsing and structured extraction

PyPI Python versions License

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 API server:

docslight web
# Health: http://127.0.0.1:8000/api/health

# Or run the same API server 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
  • API server — Local Flask backend exposing parse, extract, preview, health, and system-info endpoints
  • Batch processingparse_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]"
+ API server 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:
    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

# API server
docslight web --host 127.0.0.1 --port 8000

API Server

DocSlight includes a local Flask API server for document processing. Frontend assets are not bundled in this package.

docslight web
python -m docslight.web_app
  • GET /api/health
  • GET /api/system-info
  • POST /api/parse
  • POST /api/extract
  • POST /api/preview

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

docslight-0.1.3.tar.gz (58.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docslight-0.1.3-py3-none-any.whl (42.7 kB view details)

Uploaded Python 3

File details

Details for the file docslight-0.1.3.tar.gz.

File metadata

  • Download URL: docslight-0.1.3.tar.gz
  • Upload date:
  • Size: 58.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for docslight-0.1.3.tar.gz
Algorithm Hash digest
SHA256 9f05ddb641f5a1853af4bba23aee14c9d1b2174115e23ebc929777a4c205cb41
MD5 e481d06fc9fdca52608397a55b2fc018
BLAKE2b-256 a480f3bcca843df273dca78baeb690fd56f424840b7a8a7e8d514f7ba9f29c78

See more details on using hashes here.

File details

Details for the file docslight-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: docslight-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 42.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for docslight-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 90441ce1803031a2abf1d7f952659d8331cca7b7d5a0a18d268115dde048f7dc
MD5 3696b99406d5b21e6666dd9181034b0b
BLAKE2b-256 9095e06ca89236d680c224fea490ba8e773193ac4b7e655d794df16624ba3225

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page