Skip to main content

Python ZUGFeRD XML implementation

Project description

This is a low-level python implementation of the ZUGFeRD XML format. ZUGFeRD is a German format for sending digital invoices. ZUGFeRD XML files are to be attached to a PDF file. This library can be used to generate or parse the contents of this XML file as well as attach it to a PDF. We do not support parsing PDF files (for now).

By low-level, we mean that this library models the ZUGFeRD data model 1:1 without any further abstractions or simplifications. You can set and parse all parameters defined in ZUGFeRD 1.0.

All output is validated against the official XSDs, but no validation of profile levels (basic, comfort, extended) is performed.



>>> from drafthorse.models.document import Document
>>> samplexml = open("sample.xml", "rb").read()
>>> doc = Document.parse(samplexml)
>>> str(
'Lieferant GmbH'


>>> from datetime import date
>>> from drafthorse.models.document import Document
>>> from drafthorse.models.note import IncludedNote

>>> doc = Document()
>>> = "urn:ferd:CrossIndustryDocument:invoice:1p0:comfort"
>>> = "RE1337"
>>> = "RECHNUNG"
>>> doc.header.type_code = "380"
>>> doc.header.issue_date_time.value =
>>> doc.header.languages.add("de")
>>> note = IncludedNote()
>>> note.content.add("Test Node 1")
>>> doc.header.notes.add(n)
>>> = "Lieferant GmbH"

>>> xml = doc.serialize()
>>> xml
b'<?xml version="1.0" encoding="UTF-8"?><rsm:CrossIndustryDocument …'

# Attach XML to an existing PDF.
# Note that the existing PDF should be compliant to PDF/A-3!
# You can validate this here:
>>> new_pdf_bytes = attach_xml(original_pdf_bytes, xml, 'BASIC')


To run the included tests:

pip install -r requirements_dev.txt
py.test tests

To automatically sort your Imports as required by CI:

pip install isort
isort -rc .

Credits and License

Maintainer: Raphael Michel <>

License of the Python code: Apache License 2.0

The PDF handling (drafthorse/ is based on the code of factur-x, Copyright 2016-2018, Alexis de Lattre <>, released under a BSD license.

The packages includes schemas and samples of the ZUGFeRD specification (.xsd and .xml files) which are owned by the Forum für elektronische Rechnungen bei der AWV e.V („FeRD“) and are released under a proprietary license that allows bundling them together with other software for free.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drafthorse-1.1.1.tar.gz (73.8 kB view hashes)

Uploaded source

Built Distribution

drafthorse-1.1.1-py3-none-any.whl (81.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page