A secure, multi-tenant PDF report generation library for Python backends — built for production.
Handles the full pipeline: data isolation, statistical analysis, chart generation, HTML rendering, and AES-256 encrypted PDF delivery.
Python · SQLAlchemy · WeasyPrint · PyPDF · Matplotlib · Seaborn · Jinja2 · Pandas · NumPy
- Multi-tenant data isolation — every query is scoped by
tenant_id; no cross-tenant leakage - AES-256 PDF encryption — passwords sourced from the database, never logged or exposed
- Automated temp file cleanup — guaranteed on success and failure via context management
- Full type hint coverage — IDE-friendly throughout
pip install -r requirements.txtWeasyPrint system dependencies:
# macOS
brew install pango cairo libffi
# Ubuntu/Debian
sudo apt-get install libpango-1.0-0 libpangocairo-1.0-0 libcairo2
# Windows
# https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#installationfrom sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from report_generator import generate_encrypted_report
engine = create_engine("sqlite:///your_database.db")
session = sessionmaker(bind=engine)()
pdf_path = generate_encrypted_report(
tenant_id=1,
session=session,
report_params={"include_charts": True, "max_transactions": 25},
report_title="Quarterly Business Report"
)Run the included demo: python demo.py
| Parameter | Type | Description |
|---|---|---|
tenant_id |
int |
Tenant to generate report for |
session |
Session |
SQLAlchemy database session |
report_params |
dict |
start_date, end_date, include_charts, max_transactions |
output_directory |
Path |
Output path (default: current dir) |
report_title |
str |
Report title |
Returns str — filesystem path to the encrypted PDF.
Raises ReportGenerationError (base) · DataFetchError · ChartGenerationError · PDFConversionError · PDFEncryptionError
tenants — id, name, pdf_password
sales_data — id, tenant_id, sale_date, category, product, quantity, unit_price, total_amount
MIT