drafthorse
Python ZUGFeRD XML implementation
What it is and what it does
drafthorse is a low-level Python implementation of the ZUGFeRD XML format, a German standard for digital B2B invoicing. It models the ZUGFeRD data structure directly without abstraction, allowing you to set and parse all parameters defined in ZUGFeRD 2.3. The library can generate ZUGFeRD XML from Python objects, parse existing ZUGFeRD XML files, validate output against official XSD schemas, and attach the resulting XML to PDF files for transmission. Profile level (basic, comfort, extended) is detected automatically from the XML data.
The library does not parse PDF files themselves—it only attaches pre-generated ZUGFeRD XML to existing PDFs. All generated XML is validated against the official schemas, though profile-level compliance is not enforced. It depends on lxml for XML handling and pypdf for PDF manipulation, keeping the dependency footprint small.
Use it for:
- Generate compliant ZUGFeRD invoices programmatically for B2B transactions in Germany and EU markets.
- Parse received ZUGFeRD XML from incoming invoices to extract seller, buyer, and line-item data.
- Embed ZUGFeRD XML into PDF/A-3 files to create machine-readable digital invoices for archival.
- Validate invoice XML against ZUGFeRD 2.3 specification before transmission or storage.
- Integrate invoice generation into billing systems like pretix to meet upcoming German B2B digital invoice requirements.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates and parses ZUGFeRD XML invoice documents, and attaches them to PDF files for digital B2B invoicing compliance.
Yes, if you need to generate or parse ZUGFeRD invoices for German or EU B2B workflows. The library is actively maintained, has low install friction, carries no known vulnerabilities, and is permissively licensed. Install with caution if your invoices require strict profile-level validation or if you need to parse PDF files directly—neither is supported.
Install
drafthorse on PyPI
pip
pip install drafthorseuv
uv add drafthorsepoetry
poetry add drafthorseInstalling drafthorse
Before you install
Low install friction with only two runtime dependencies (lxml and pypdf). Actively maintained with recent releases; maintainers note turnaround on issues may be longer than usual due to competing priorities, but the library is kept functional for production use in the pretix-zugferd module.
License in practice
Apache License 2.0 permits commercial and private use with minimal restrictions. PDF handling code is derived from factur-x (BSD license). Bundled XSD schemas and samples are owned by FeRD and released under a proprietary license that allows free bundling.
Quickstart
from drafthorse.models.document import Document
samplexml = open("sample.xml", "rb").read()
doc = Document.parse(samplexml)
print(doc.trade.agreement.seller.name)
Requires a valid ZUGFeRD XML file to parse; PDF attachment requires an existing PDF/A-3 compliant PDF file.
Verify before relying
- Whether strict parsing mode (default True) is appropriate for your invoice sources or if lenient parsing is needed.
- Performance characteristics when handling large batches of invoices or complex line items.
- Whether all ZUGFeRD 2.3 parameters your use case requires are fully supported.
Package facts
| License | Apache License (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — lxml, pypdf |
| Maintenance | actively maintained — 333 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 132,686/month — #11,542 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: drafthorse-2025.2.0-py3-none-any.whl
Keywords: xml, banking, sepa
Tags
More Markup packages
PyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
markdown-it-pyA Python markdown parser that converts markdown…
permissive · top 100 on PyPI
beautifulsoup4Beautiful Soup parses HTML and XML documents…
permissive · top 100 on PyPI
et-xmlfileet_xmlfile writes large XML files with minimal…
permissive · top 1,000 on PyPI
tomlkitParses and edits TOML files while preserving…
permissive · top 1,000 on PyPI
docstring-parserParses Python docstrings in ReST, Google,…
permissive · top 1,000 on PyPI
BrazilFiscalReportConverts Brazilian electronic invoice XML files…
agpl · top 15,000 on PyPI
factur-xGenerates, validates, and extracts Factur-X,…
permissive · top 15,000 on PyPI
sepaxmlGenerates SEPA XML payment files for direct…
permissive · top 15,000 on PyPI
unittest-xml-reportingA unittest test runner that exports test…
permissive · top 5,000 on PyPI
pdfminerExtracts text and layout information from PDF…
permissive · top 15,000 on PyPI
cloudmersive-convert-api-clientA Python client library for the Cloudmersive…
unclear · top 15,000 on PyPI
endesiveEndesive signs and verifies digital signatures…
unclear · top 15,000 on PyPI
xlwtGenerates Microsoft Excel 97–2003 XLS…
permissive · top 5,000 on PyPI
fintsA pure-Python implementation of the FinTS 3.0…
copyleft · top 15,000 on PyPI
kreuzbergExtracts text, tables, images, and metadata…
permissive · top 15,000 on PyPI