01 · GET STARTED
Install eDocAPI
Use Python 3.10–3.13 and a virtual environment. Install the core package first; add optional extras only when your project needs them.
python -m venv .venv
# Windows PowerShell
.\.venv\Scripts\Activate.ps1
# macOS / Linux
# source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install edocapi
eDocAPI has two main building blocks: Document processes files in Python, while App exposes operations as HTTP endpoints.
02 · THE DOCUMENT TOOLKIT
Process a file directly
Create a Document from a path, inspect it, and call the operation you need. File outputs are returned as Documents; text and metadata operations return Python values.
from edocapi import Document
doc = Document("report.docx")
print(doc.type, doc.size)
pdf = doc.to_pdf()
print("PDF:", pdf.path)
text = doc.extract_text()
details = doc.info()
print(text[:500])
print(details)
Convert and extract
Use to_pdf(), to_text(), to_html(), and extract_text() to get a useful output from supported documents.
Compress and combine
Use compress(target_size=...) for PDFs or images, and Document.merge([...]) to combine PDF files.
OCR
Call ocr(lang="eng") for recognition. Tesseract requires the ml extra and the Tesseract program; Paddle uses the optional structured OCR extra.
Create content in memory
Build input without a temporary source file with Document.html(...), Document.markdown(...), or Document.text(...).
03 · FORMATS AND OPTIONAL EXTRAS
Choose the operation that fits the file
Capabilities depend on input format. Check Document.supported_types() in code and install extras for enhanced rendering or OCR.
| Input | Typical operations | Notes |
|---|---|---|
| Extract, OCR, compress, merge, convert pages to images | Merge accepts PDFs; PDF image rendering needs Poppler. | |
| DOCX | Convert to PDF, extract text, inspect info | DOCX PDF output uses ReportLab in the core package. |
| HTML / Markdown | Convert to PDF, extract source text | The html extra enables WeasyPrint rendering. |
| TXT | Convert to PDF, extract text | Basic text workflows need no OCR extra. |
| JPEG / PNG / WebP | Convert, OCR, compress | OCR needs an engine; compression may change format to meet a target. |
python -m pip install "edocapi[html]" # enhanced HTML / Markdown PDF
python -m pip install "edocapi[pdf-images]" # PDF page images (also install Poppler)
python -m pip install "edocapi[ml]" # Tesseract OCR helpers
python -m pip install "edocapi[structured-ocr]" # PaddleOCR; Python 3.13 or earlier
python -m pip install "edocapi[server]" # Uvicorn server
04 · BUILD AN HTTP API
Expose your workflow with App
Decorate Python functions with @app.get or @app.post. Upload fields such as file and files are provided to your handler; returning a Document sends a file response, and returning a dictionary sends JSON.
from edocapi import App, Document
app = App(max_file_size="10MB")
@app.post("/convert")
def convert(file):
return Document(file).to_pdf()
@app.post("/extract")
def extract(file):
return {"text": Document(file).extract_text()}
@app.post("/compress")
def compress(file, target_size: int | None = None):
return Document(file).compress(target_size=target_size)
@app.post("/ocr")
def ocr(file, lang: str = "eng"):
return {"text": Document(file).ocr(lang=lang)}
OCR’s HTTP route is disabled by default; enable it with App(enable_ocr=True). The library OCR method remains available independently of that route setting.
05 · LIMITS AND SAFE HANDLING
Set boundaries before you serve uploads
The framework validates file content, checks file signatures, sanitizes names, and cleans managed temporary files. Configure a smaller upload limit and rate limit for your own workload.
app = App(max_file_size="10MB", max_request_size="30MB")
app.limits(100, per="minute")
@app.post("/ocr", limit="5/minute")
def ocr(file):
return {"text": Document(file).ocr()}
- 400 — missing upload or invalid document.
- 413 — file or full request body exceeds its configured limit.
- 415 — unsupported file type or signature mismatch.
- 429 — rate limit exceeded; check the
Retry-Afterheader.
Treat uploads as untrusted input. Renderers block local and remote resource fetching. Don’t raise size limits or disable validation unless your service has a clear reason and the capacity to handle it.
06 · CLI AND DEPLOYMENT
Use the same tools from your terminal
edocapi --version
edocapi convert report.docx -o report.pdf
edocapi extract report.pdf
edocapi info image.png
edocapi ocr scan.png --lang eng
edocapi compress large.pdf --target 500KB
# Start your App locally
uvicorn main:app --reload
For deployment, install edocapi[server] and run your ASGI app with Uvicorn bound to 0.0.0.0 and the port supplied by your host. Keep debug mode off in production and set proxy request limits to match the app.
07 · CONTINUE LEARNING
Work through the complete course
The textbook in the assets folder is a hands-on course based on eDocAPI 0.2.0. It covers the Document class, supported formats, OCR, App routes, limits, errors, the CLI, security, testing, and three capstone projects. Type and run the exercises as you go.
Download eDocAPI Developer Course