skillfed

drafthorse

Python ZUGFeRD XML implementation

drafthorse v2025.2.0 132.7K downloads/30d#11,542 on PyPI176
Permissive license Apache License Active released

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 drafthorse

uv

uv add drafthorse

poetry

poetry add drafthorse

Installing 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

Intended Audience :: DevelopersIntended Audience :: Other AudienceLicense :: OSI Approved :: Apache Software LicenseProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

zugferd xml invoice generationdigital invoice format pythonb2b invoice xml parserfactur-x pdf attachmentgerman invoice standardzugferd pdf embeddingxml invoice validation
invoice-generationxml-processingcompliance

More Markup packages