Python ZUGFeRD XML implementation
pip install drafthorsedrafthorse -- Basic ZUGFeRD implementation in Python
.. image:: https://github.com/pretix/python-drafthorse/actions/workflows/tests.yml/badge.svg :target: https://github.com/pretix/python-drafthorse/actions/workflows/tests.yml
.. image:: https://codecov.io/gh/pretix/python-drafthorse/branch/master/graph/badge.svg :target: https://codecov.io/gh/pretix/drafthorse
.. image:: http://img.shields.io/pypi/v/drafthorse.svg :target: https://pypi.python.org/pypi/drafthorse
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 tries to model the ZUGFeRD data model 1:1 without any further abstractions or simplifications. You can set and parse all parameters defined in ZUGFeRD 2.3. To see which parameters are defined, please refer to the official ZUGFeRD specification, there is no documentation for this library that reiterates it.
All output is validated against the official XSDs, but no validation of profile levels (basic, comfort, extended) is performed.
The profile level is detected automatically based on the XML data and added to the PDF metadata.
Maintenance note
With the possibly upcoming legal obligation to use digital formats for all B2B invoices in Germany, interest in this library is increasing. We built this library to ble able to use it in the pretix-zugferd module and we are planning to keep maintaining the library. However, it is not our core business and turnaround time on issus or PR reviews might be longer than usual due to other priorities. We do not offer paid consulting services around this library.
Usage
Parsing::
from drafthorse.models.document import Document
samplexml = open("sample.xml", "rb").read()
doc = Document.parse(samplexml)
print(doc.trade.agreement.seller.name)
taskes a boolean parameter which defaults to . This means that the parser will raise an error if it encounters any unknown element. If you set it to , the parser will not raise an error and parse whatever it can.