Skip to main content

ZipReport

Tests pypi license


Documentation: https://zipreport.github.io/zipreport/


Transform HTML templates into beautiful PDF or MIME reports, with full CSS and client Javascript support, under a permissive license.

PagedJS Examples:

Example Description Output
pagedjs Basic PagedJS with matplotlib graphics and radar charts PDF
executive_report Modern executive report with KPIs, charts, and TOC PDF
product_brochure Software product brochure with pricing and testimonials PDF
analytics_dashboard Single-page site analytics dashboard (A4 landscape) PDF

Highlights:

  • Create your reports using Jinja templates;
  • Customize the Jinja Environment();
  • Dynamic image support (embedding of runtime-generated images);
  • Reports are packed in a single file for easy distribution or bundling;
  • Optional MIME processor to embed resources in a single email message;
  • Support for browser-generated JS content (with zipreport-server);
  • Support for headers, page numbers and ToC (using PagedJS, see details below);

Requirements:

  • Python >= 3.10
  • Jinja2 >= 3.1
  • Compatible backend for PDF generation (zipreport-server or WeasyPrint);

v2.x.x breaking changes

Starting with zipreport 2.0.0, support for the electron-based zipreport-cli rendering backend is removed; using a zipreport-server version 2.0.0 or later - preferably using a docker container, is now the recommended approach.

The behavior of the JS event approach has also changed; PDF rendering can now be triggered via console message, instead of dispatching an event. If you use JS events to trigger rendering, you need to update your templates.

Old method:

    (
...)
// signal PDF generation after all DOM changes are performed
document.dispatchEvent(new Event('zpt-view-ready'))
(...)

New method, starting with v2.0.0:

    (
...)
// signal PDF generation after all DOM changes are performed
console.log('zpt-view-ready')
(...)

Installation

Installing via pip:

$ pip install zipreport-lib
TL;DR; example

Using zipreport-server backend to render a report file:

from zipreport import ZipReport
from zipreport.report import ReportFileLoader

# existing zpt template
report_file = "report.zpt"

# output file
output_file = "result.pdf"

# template variables
report_data = {
    'title': "Example report using Jinja templating",
    'color_list': ['red', 'blue', 'green'],
    'description': 'a long text field with some filler description',
}

# load report from file
zpt = ReportFileLoader.load(report_file)

# initialize api client
client = ZipReport("https://127.0.0.1:6543", "secretKey")
job = client.create_job(zpt)

# generate a PDF by calling the processor, using the API client
# this method returns a JobResult
result = client.render(job, report_data)

# if PDF generation was successful, save to file
if result.success:
    with open(output_file, 'wb') as rpt:
        rpt.write(result.report.read())

Testing

Running the test suite:

$ pip install pytest pillow
$ pytest tests/

Integration tests that require a running zipreport-server are skipped by default. To enable them:

$ ZIPREPORT_SERVER=1 pytest tests/

The server host, port and API key can be configured via environment variables:

  • ZIPREPORT_API_PORT - server port (default: 6543)
  • ZIPREPORT_API_KEY - API key (default: somePassword)

Paged.js

PagedJS is an amazing javascript library that performs pagination of HTML documents for print, under MIT license. It acts as polyfill for W3C specification for print, and allows the creation of headers, footers, page numbers, table of contents, etc. in the browser.

To use PagedJS capabilities, zipreport-server must be used as a backend.

Available backends

Zipreport-Server

zipreport-server is a headless browser daemon orchestrator, designed specifically to work with ZipReport. It can be either installed locally or run via docker.

zipreport-server is the only supported backend that enables full usage of client-side JavaScript and leveraging the PagedJS capabilities.

WeasyPrint

This backend is provided for compatibility. For new projects, please use zipreport-server.

WeasyPrint is a popular Python library to generate PDFs from HTML. It doesn't support JavaScript, and CSS is limited.

Sponsors

The ZipReport Project is sponsored exclusively by BlackShield

License

MIT License - see LICENSE file for details

Metadata

Release files for zipreport-lib 2.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zipreport-lib 2.3.0
File Size Uploaded Provenance
zipreport_lib-2.3.0.tar.gz 48.0 kB Without provenance Details

Release files / zipreport_lib-2.3.0.tar.gz

Download URL zipreport_lib-2.3.0.tar.gz
Size 48.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c130b00707d7e8404728d47e87ad3124e3b1d9e14a96aec5ab983ebc23d4796c
BLAKE2b-256 checksum
How to use checksums
089a75ea5c791862439029ec52181e2c4310341a4d848e1386b92dd9f91d74ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for zipreport-lib 2.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page