Skip to main content

Python ZUGFeRD XML implementation

Project description

https://travis-ci.com/pretix/python-drafthorse.svg?branch=master https://codecov.io/gh/pretix/python-drafthorse/branch/master/graph/badge.svg http://img.shields.io/pypi/v/drafthorse.svg

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.

Usage

Parsing:

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

Generating:

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

>>> doc = Document()
>>> doc.context.guideline_parameter.id = "urn:ferd:CrossIndustryDocument:invoice:1p0:comfort"
>>> doc.header.id = "RE1337"
>>> doc.header.name = "RECHNUNG"
>>> doc.header.type_code = "380"
>>> doc.header.issue_date_time.value = date.today()
>>> doc.header.languages.add("de")
>>> note = IncludedNote()
>>> note.content.add("Test Node 1")
>>> doc.header.notes.add(n)
>>> doc.trade.agreement.seller.name = "Lieferant GmbH"

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

>>> new_pdf_bytes = attach_xml(original_pdf_bytes, xml, 'BASIC')

Development

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 <michel@rami.io>

License: Apache License 2.0

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.0.0.tar.gz (72.6 kB view hashes)

Uploaded Source

Built Distribution

drafthorse-1.0.0-py3-none-any.whl (79.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page