
DocStrange converts documents to Markdown, JSON, CSV, and HTML quickly and accurately.

☁️ Free Cloud Processing upto 10000 docs per month !
Extract documents data instantly with the cloud processing - no complex setup needed🔒 Local Processing !
Usegpumode for 100% local processing - no data sent anywhere, everything stays on your machine.
August 2025
Convert and extract data from PDF, DOCX, images, and more into clean Markdown and structured JSON. Plus: Advanced table extraction, 100% local processing, and a built-in web UI.
DocStrange is a Python library for converting a wide range of document formats—including PDF, DOCX, PPTX, XLSX, and images — into clean, usable data. It produces LLM-optimized Markdown, structured JSON (with schema support), HTML, and CSV outputs, making it an ideal tool for preparing content for RAG pipelines and other AI applications.
The library offers both a powerful cloud API and a 100% private, offline mode that runs locally on your GPU. Developed by Nanonets, DocStrange is built on a powerful pipeline of OCR and layout detection models and currently requires Python >=3.8.
To report a bug or request a feature, please file an issue. To ask a question or request assistance, please use the discussions forum.
DocStrange focuses on end-to-end document understanding (OCR → layout → tables → clean Markdown or structured JSON) that you can run 100% locally. It is designed to deliver high-quality results from scans and photos without requiring the integration of multiple services.
DocStrange offers a completely private, local processing option and gives you full control over the conversion pipeline.DocStrange is a ready-to-use parsing pipeline, not just a framework. It handles the complex OCR and layout analysis so you don't have to build it yourself.DocStrange is specifically built for robust OCR on scans and phone photos, not just digitally-native PDFs.Try the live demo: Test DocStrange instantly in your browser with no installation required at docstrange.nanonets.com
See it in action:
Install the library using pip:
pip install docstrange
💡 New to DocStrange? Try the online demo first - no installation needed!
1. Convert any Document to LLM-Ready Markdown
This is the most common use case. Turn a complex PDF or DOCX file into clean, structured Markdown, perfect for RAG pipelines and other LLM applications.
from docstrange import DocumentExtractor
# Initialize extractor (cloud mode by default)
extractor = DocumentExtractor()
# Convert any document to clean markdown
result = extractor.extract("document.pdf")
markdown = result.extract_markdown()
print(markdown)
2. Extract Structured Data as JSON
Go beyond plain text and extract all detected entities and content from your document into a structured JSON format.
from docstrange import DocumentExtractor
# Extract document as structured JSON
extractor = DocumentExtractor()
result = extractor.extract("document.pdf")
# Get all important data as flat JSON
json_data = result.extract_data()
print(json_data)
3. Extract Specific Fields from a PDF or Invoice
Target only the key-value data you need, such as extracting the invoice_number or total_amount directly from a document.
from docstrange import DocumentExtractor
# Extract only the fields you need
extractor = DocumentExtractor()
result = extractor.extract("invoice.pdf")
# Specify exactly which fields to extract
fields = result.extract_data(specified_fields=[
"invoice_number", "total_amount", "vendor_name", "due_date"
])
print(fields)
4. Extract with Custom JSON Schema
Ensure the structure of your output by providing a custom JSON schema. This is ideal for getting reliable, nested data structures for applications that process contracts or complex forms.
from docstrange import DocumentExtractor
# Extract data conforming to your schema
extractor = DocumentExtractor()
result = extractor.extract("contract.pdf")
# Define your required structure
schema = {
"contract_number": "string",
"parties": ["string"],
"total_value": "number",
"start_date": "string",
"terms": ["string"]
}
structured_data = result.extract_data(json_schema=schema)
print(structured_data)
Local Processing
For complete privacy and offline capability, run DocStrange entirely on your own machine using GPU processing.
# Force local GPU processing (requires CUDA)
extractor = DocumentExtractor(gpu=True)
💡 Want a GUI? Run the simple, drag-and-drop local web interface for private, offline document conversion.
For users who prefer a graphical interface, DocStrange includes a powerful, self-hosted web UI. This allows for easy drag-and-drop conversion of PDF, DOCX, and other files directly in your browser, with 100% private, offline processing on your own GPU. The interface automatically downloads required models on its first run.
pip install "docstrange[web]"
# Method 1: Using the CLI command
docstrange web
# Method 2: Using Python module
python -m docstrange.web_app
# Method 3: Direct Python import
python -c "from docstrange.web_app import run_web_app; run_web_app()"
http://localhost:8000 (or the port shown in the terminal)# Run on a different port
docstrange web --port 8080
python -c "from docstrange.web_app import run_web_app; run_web_app(port=8080)"
# Run with debug mode for development
python -c "from docstrange.web_app import run_web_app; run_web_app(debug=True)"
# Make accessible from other devices on the network
python -c "from docstrange.web_app import run_web_app; run_web_app(host='0.0.0.0')"
# Use a different port
docstrange web --port 8001
GPU Not Available:
The interface automatically detects GPU availability
Error will be thrown
Model Download Issues:
Models are downloaded automatically on first startup
Download progress is shown in the terminal
Installation Issues:
# Install with all dependencies
pip install -e ".[web]"
# Or install Flask separately
pip install Flask
Cloud Alternative
Need cloud processing? Use the official DocStrange Cloud service: 🔗 docstrange.nanonets.com
You can use DocStrange in three main ways: as a simple Web Interface, as a flexible Python Library, or as a powerful Command Line Interface (CLI). This section provides a summary of the library's key capabilities, followed by detailed guides and examples for each method.
DocStrange natively handles a wide variety of formats, returning the most appropriate output for each.
from docstrange import DocumentExtractor
extractor = DocumentExtractor()
# PDF document
pdf_result = extractor.extract("report.pdf")
print(pdf_result.extract_markdown())
# Word document
docx_result = extractor.extract("document.docx")
print(docx_result.extract_data())
# Excel spreadsheet
excel_result = extractor.extract("data.xlsx")
print(excel_result.extract_csv())
# PowerPoint presentation
pptx_result = extractor.extract("slides.pptx")
print(pptx_result.extract_html())
# Image with text
image_result = extractor.extract("screenshot.png")
print(image_result.extract_text())
# Web page
url_result = extractor.extract("https://example.com")
print(url_result.extract_markdown())
b. Extract Tables to CSV
Easily extracts all tables from a document into a clean CSV format.
# Extract all tables from a document
result = extractor.extract("financial_report.pdf")
csv_data = result.extract_csv()
print(csv_data)
c. Extract Specific Fields & Structured Data
You can go beyond simple conversion and extract data in the exact structure you require. There are two ways to do this. You can either target and pull only the key-value data you need or ensure the structure of your output by providing a custom JSON schema.
```python
result = extractor.extract("invoice.pdf")
extracted = result.extract_data(specified_fields=[ "invoice_number", "total_amount", "vendor_name", "due_date" ])
schema = { "invoic
$ claude mcp add docstrange \
-- python -m otcore.mcp_server <graph>