--- id: drafthorse version: "2025.2.0" license: Apache License license_treatment: permissive maintenance: active --- # drafthorse — Python ZUGFeRD XML implementation License: permissive · Maintenance: active · Downloads: 132.7K/mo ## 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 above — 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 pip install drafthorse uv add drafthorse 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: unspecified - Install friction: low - Maintenance: active - Downloads: 132.7K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags zugferd xml invoice generation, digital invoice format python, b2b invoice xml parser, factur-x pdf attachment, german invoice standard, zugferd pdf embedding, xml invoice validation, invoice-generation, xml-processing, compliance [View on SkillFed](https://skillfed.io/packages/drafthorse) · [View on PyPI](https://pypi.org/project/drafthorse/)