pydyf
A low-level PDF generator for Python based on the PDF 1.7 specification.
Repository Health
Technical Analysis
pydyf is a small, low-level PDF generator written in pure Python and based on version 1.7 of the PDF specification. Rather than offering high-level page-layout helpers, it exposes the underlying PDF object model — dictionaries, streams, and the cross-reference table — so you can assemble a PDF file precisely from its building blocks.
Developed by CourtBouillon, the team behind WeasyPrint, pydyf serves as the PDF-writing foundation for higher-level rendering tools while remaining usable on its own when you need exact control over the output.
What You Get
- Python classes for core PDF primitives (Dictionary, Stream, Array, String, Number)
- A PDF document object that manages objects and the cross-reference table
- Direct control over page content streams and PDF structure
- A dependency-free, pure-Python implementation targeting Python 3.10+
Common Use Cases
- Serving as the PDF-writing backend for a rendering engine
- Generating PDFs with an exact, hand-controlled object structure
- Learning or experimenting with the internals of the PDF format
Under The Hood
Architecture - pydyf represents PDF’s low-level types as a small hierarchy of Python objects (Object subclasses such as Dictionary, Stream, Array, String, and Number). A PDF instance collects these objects, assigns them object numbers, and, when written, emits the file body followed by the cross-reference table and trailer that let a reader locate each object. The design mirrors the PDF 1.7 document model rather than abstracting over it.
Tech Stack - 100% Python with no third-party runtime dependencies, targeting Python 3.10+ and tested on both CPython and PyPy. Packaging follows CourtBouillon’s standard PEP 517/518 layout, and documentation is published separately at doc.courtbouillon.org.
Code Quality - The codebase is deliberately compact (~42 KB of Python) and has been maintained steadily since 2020 across 18 releases by the WeasyPrint maintainers. Its role as the PDF backend for a widely used renderer gives it strong real-world test exposure, and it uses a clear, focused object model that is easy to audit.
API Design - The API stays close to the PDF specification, which trades hand-holding for precision: callers construct primitive objects explicitly and assemble them into a document. This makes it powerful for tools that need exact output, while higher-level libraries typically wrap it to hide the low-level details from end users.