Skip to content

shreyescodes/report-generation

Repository files navigation

Report Generator

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.


Tech Stack

Python · SQLAlchemy · WeasyPrint · PyPDF · Matplotlib · Seaborn · Jinja2 · Pandas · NumPy


Highlights

  • 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

Installation

pip install -r requirements.txt

WeasyPrint 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#installation

Quick Start

from 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


API

generate_encrypted_report()

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


Database Schema

tenantsid, name, pdf_password

sales_dataid, tenant_id, sale_date, category, product, quantity, unit_price, total_amount


License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors