DocuGen
DocuGen is a production-grade, local-first Python library that transforms structured application data into professionally formatted, audit-ready documents across PDF, Word DOCX, responsive HTML, and Excel XLSX — entirely without cloud dependencies, API subscriptions, or external render services.
Whether generating hospital billing receipts, legal NDAs, employment contracts, laboratory diagnostic reports, or financial invoices, DocuGen combines strict schema validation, cryptographic digital signing, dynamic barcode/QR generation, multi-language localization, and high-throughput async orchestration into a single Python library.
from docugen import generate_document, DigitalSignatureConfig
result = generate_document(
data={
"invoice_number": "INV-2026-901",
"date": "2026-10-02",
"buyer_name": "Acme Health Systems",
"seller_name": "Apollo Care Solutions",
"items": [{"description": "Specialist Consultation", "quantity": 1, "unit_price": 450.0, "total": 450.0}],
"total_amount": 450.0,
},
template="invoice",
output="pdf", # "pdf" | "docx" | "html" | "xlsx"
output_path="output/invoice.pdf",
watermark={"status": "PAID", "rotation": 45, "opacity": 0.15},
digital_signature=DigitalSignatureConfig(
signer_name="Dr. Marcus Brody, MD",
reason="Certified Clinical Billing Approval"
)
)
# → output/invoice.pdf ✓ (Signed, watermarked, audit-verified)
✨ Core Highlights & Features
| Capability | What It Does |
|---|---|
| Multi-Format Matrix | Render the same data into PDF (vector layout), Word DOCX (editable), HTML (responsive web & email), or Excel XLSX (styled multi-column grids). |
| Cryptographic Digital Signatures | Generate 2048-bit RSA X.509 self-signed certificates, sign PDFs with SHA-256 + RSA-PKCS1v15 tamper-evident blocks, and verify document integrity with verify_pdf_signature(). |
| Dynamic 1D Barcodes & 2D QR Codes | Pure-Python Code128 barcodes and QR codes embedded seamlessly as PDF flowables, DOCX inline pictures, and HTML base64 SVGs without missing binary dependencies. |
| Advanced Watermarks | Diagonal status watermarks (PAID, CONFIDENTIAL, DRAFT, VOID) with customizable opacity and rotation, plus centered translucent image logos/crests. |
| i18n & Currency in Words | Localized formatting and automatic conversion of monetary amounts into words for both Indian (Lakhs/Crores) and Western (Millions/Billions) numbering systems, with translation dictionaries for English, Spanish, French, German, and Hindi. |
| High-Throughput Async Engine | Non-blocking generate_document_async() and concurrent generate_documents_batch() offloaded to thread worker pools for FastAPI, Starlette, Celery, and background queues. |
| Local-First & Zero Cloud Leakage | 100% of generation occurs inside your Python process. Zero client data is transmitted over the network — compliant with HIPAA, GDPR, and air-gapped security enclaves. |
| AI Agent & Chatbot Ready | Pre-built for LLM Tool Use / Function Calling (Gemini, OpenAI, Claude, LangChain, LangGraph). AI bots can reliably generate certified files directly in user chats. |
| Schema Validation & Hybrid Classification | Field-level type/range/regex checks and automatic document classification from raw payload dictionaries. |
📦 Installation
From GitHub:
pip install git+https://github.com/swayamprabhu2005/DocuGen.git
From Local Source (Editable):
git clone https://github.com/swayamprabhu2005/DocuGen.git
cd DocuGen
pip install -e .
From PyPI (once published):
pip install docugen-library
Optional Extras:
pip install "docugen-library[dev]" # Adds pytest, ruff, mypy for development
pip install "docugen-library[ml]" # Adds scikit-learn for advanced ML-based classification
pip install "docugen-library[nlp]" # Adds spaCy for NLP entity extraction
🚀 Quick Start Guide
1. Generating Different Formats from One Schema
import docugen
data = {
"report_title": "Q3 Financial Diagnostics & Clinical Review",
"prepared_by": "Finance & Compliance Division",
"organization": "Apollo Health Partners",
"report_date": "2026-10-02",
"executive_summary": "Quarterly overview of diagnostic volumes, surgical yields, and patient satisfaction metrics.",
}
# Generate PDF
docugen.generate_document(data, template="business_report", output="pdf", output_path="report.pdf")
# Generate Microsoft Word DOCX
docugen.generate_document(data, template="business_report", output="docx", output_path="report.docx")
# Generate Responsive HTML
docugen.generate_document(data, template="business_report", output="html", output_path="report.html")
# Generate Excel Spreadsheet
docugen.generate_document(data, template="business_report", output="xlsx", output_path="report.xlsx")
2. Digital Signatures & Cryptographic Verification
from docugen import generate_document, DigitalSignatureConfig, verify_pdf_signature
# 1. Sign during PDF generation
result = generate_document(
data={"invoice_number": "INV-100", "total_amount": 5000.0, "items": []},
template="invoice",
output="pdf",
output_path="signed_contract.pdf",
digital_signature=DigitalSignatureConfig(
signer_name="Dr. Marcus Brody, MD",
reason="Clinical Billing Certification",
location="Mumbai Hospital Enclave",
)
)
# 2. Cryptographically verify anywhere
verification = verify_pdf_signature("signed_contract.pdf")
print("Authentic:", verification["valid"]) # True
print("Signer:", verification["signer"]) # Dr. Marcus Brody, MD
print("SHA-256 Digest:", verification["digest"]) # e.g. b1756a59...
If anyone modifies even a single byte of the signed PDF, verify_pdf_signature() flags the file as tampered (valid=False).
3. Number-to-Words & Multi-Currency (i18n)
from docugen import amount_to_words, format_currency
# Indian Numbering (Lakhs & Crores)
print(amount_to_words(1450250.75, currency="INR"))
# → "Fourteen Lakh Fifty Thousand Two Hundred Fifty Rupees and Seventy Five Paise Only"
# Western Numbering (Millions & Billions)
print(amount_to_words(1450250.75, currency="USD"))
# → "One Million Four Hundred Fifty Thousand Two Hundred Fifty Dollars and Seventy Five Cents Only"
# Formatted currency prefixes
print(format_currency(1450250.75, currency="INR")) # ₹1,450,250.75
print(format_currency(1450250.75, currency="EUR")) # €1,450,250.75
4. High-Throughput Async & Batch Processing
import asyncio
from docugen import generate_document_async, generate_documents_batch
async def main():
# Single non-blocking generation (perfect for FastAPI routes)
res = await generate_document_async(
data={"invoice_number": "INV-001", "total_amount": 250.0},
template="invoice",
output_path="async_invoice.pdf"
)
# Parallel batch generation with bounded concurrency
jobs = [
{"template": "invoice", "data": {"invoice_number": f"INV-{i}", "total_amount": i * 100}, "output_path": f"inv_{i}.pdf"}
for i in range(10)
]
results = await generate_documents_batch(jobs, max_concurrency=4)
print(f"Generated {len(results)} documents concurrently!")
asyncio.run(main())
🤖 Chatbot & AI Agent Tool Integration
DocuGen functions have strict type hints, making it effortless to register as a function/tool for Gemini, OpenAI, Claude, LangChain, or custom LLM bots:
# LLM Tool Schema
tools = [{
"type": "function",
"function": {
"name": "generate_patient_document",
"description": "Generate an official medical bill, prescription, or lab report PDF with barcodes and QR codes.",
"parameters": {
"type": "object",
"properties": {
"patient_name": {"type": "string"},
"services": {"type": "array", "items": {"type": "object"}},
"total_amount": {"type": "number"},
"document_type": {"type": "string", "enum": ["invoice", "lab_report", "prescription"]}
},
"required": ["patient_name", "total_amount"]
}
}
}]
# Webhook / Handler
def on_chatbot_tool_call(arguments: dict):
file_path = f"generated/{arguments['patient_name']}_record.pdf"
docugen.generate_document(
data=arguments,
template=arguments.get("document_type", "invoice"),
output="pdf",
output_path=file_path,
watermark={"status": "PAID"}
)
return {"download_url": f"https://myhealth.app/files/{file_path}"}
🖥️ Command-Line Interface (CLI)
DocuGen includes a full-featured CLI:
# Generate a document from a JSON file
docugen generate --template invoice --data billing.json --output invoice.pdf --format pdf
# Validate payload data against document schema without rendering
docugen validate --template nda --data agreement.json
# Inspect available templates and schemas
docugen templates list
docugen schemas list
docugen schemas show invoice
📖 In-Depth Documentation
For complete API documentation, custom template creation, advanced flowables, and real-world deployment patterns, read the Comprehensive User & Developer Guide.
🧪 Running Tests
# Run full unit and integration test suite
pytest tests/ -v
# Run verification script with all advanced features
python D:/Test/New/test_new_features.py
📝 License
Licensed under the Apache License 2.0. Free for commercial and open-source use.
Metadata
Release files for docugen-library 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| docugen_library-0.1.0.tar.gz | 73.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| docugen_library-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 160.6 kB
Release files / docugen_library-0.1.0.tar.gz
| Download URL | docugen_library-0.1.0.tar.gz |
|---|---|
| Size | 73.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9821abe0359423fb14fac6916540396384160ec6a60db8621494d6d8a4d0168
|
|
BLAKE2b-256 checksum How to use checksums |
e779b7bbf743dd6b64c41eb60cd319387c0b1e15568a836558471a39f4d0e8c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.8
|
Release files / docugen_library-0.1.0-py3-none-any.whl
| Download URL | docugen_library-0.1.0-py3-none-any.whl |
|---|---|
| Size | 86.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
246c54723b0f47f24d2d22620026bf47b11617aa6ef7d70d7e40de64a057adbd
|
|
BLAKE2b-256 checksum How to use checksums |
f60ee3f1a6e3935f4f00cc41f11ca68b0e36f35dae53068027f94a5a542811dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.8
|