{"id":20055060,"url":"https://github.com/pretix/python-drafthorse","last_synced_at":"2025-05-16T04:02:19.562Z","repository":{"id":52213208,"uuid":"152552681","full_name":"pretix/python-drafthorse","owner":"pretix","description":"Pure-python ZUGFeRD implementation","archived":false,"fork":false,"pushed_at":"2025-04-17T09:27:48.000Z","size":2678,"stargazers_count":134,"open_issues_count":9,"forks_count":26,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-17T23:35:36.301Z","etag":null,"topics":["invoicing","python","xml","zugferd"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pretix.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-10-11T07:52:27.000Z","updated_at":"2025-04-17T09:27:51.000Z","dependencies_parsed_at":"2024-01-19T16:57:16.276Z","dependency_job_id":"2dbbc32d-a2bc-4d05-8c3a-5c3080f792d1","html_url":"https://github.com/pretix/python-drafthorse","commit_stats":{"total_commits":74,"total_committers":4,"mean_commits":18.5,"dds":0.3513513513513513,"last_synced_commit":"5e21c82d2ec34c83307f5fc339f3bcf71eb8ae77"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pretix%2Fpython-drafthorse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pretix%2Fpython-drafthorse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pretix%2Fpython-drafthorse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pretix%2Fpython-drafthorse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pretix","download_url":"https://codeload.github.com/pretix/python-drafthorse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254464890,"owners_count":22075570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["invoicing","python","xml","zugferd"],"created_at":"2024-11-13T12:45:49.559Z","updated_at":"2025-05-16T04:02:19.514Z","avatar_url":"https://github.com/pretix.png","language":"Python","funding_links":[],"categories":["Electronic Invoicing"],"sub_categories":[],"readme":"drafthorse -- Basic ZUGFeRD implementation in Python\n====================================================\n\n.. image:: https://github.com/pretix/python-drafthorse/actions/workflows/tests.yml/badge.svg\n   :target: https://github.com/pretix/python-drafthorse/actions/workflows/tests.yml\n\n.. image:: https://codecov.io/gh/pretix/python-drafthorse/branch/master/graph/badge.svg\n   :target: https://codecov.io/gh/pretix/drafthorse\n\n.. image:: http://img.shields.io/pypi/v/drafthorse.svg\n   :target: https://pypi.python.org/pypi/drafthorse\n\nThis is a low-level python implementation of the ZUGFeRD XML format. ZUGFeRD is a German\nformat for sending digital invoices. ZUGFeRD XML files are to be attached to a PDF\nfile. This library can be used to generate or parse the contents of this XML file as well as\nattach it to a PDF. We do not support parsing PDF files (for now).\n\nBy low-level, we mean that this library tries to model the ZUGFeRD data model 1:1 without any\nfurther abstractions or simplifications. You can set and parse all parameters defined in ZUGFeRD\n2.3. To see which parameters are defined, please refer to the official ZUGFeRD specification,\nthere is no documentation for this library that reiterates it.\n\nAll output is validated against the official XSDs, but no validation of profile levels\n(basic, comfort, extended) is performed.\n\nThe profile level is detected automatically based on the XML data and added to the PDF metadata.\n\nMaintenance note\n----------------\n\nWith the possibly upcoming legal obligation to use digital formats for all B2B invoices in\nGermany, interest in this library is increasing. We built this library to ble able to use it\nin the [pretix-zugferd](https://github.com/pretix/pretix-zugferd) module and we are planning\nto keep maintaining the library. However, it is not our core business and turnaround time on\nissus or PR reviews might be longer than usual due to other priorities. We do not offer paid\nconsulting services around this library.\n\nUsage\n-----\n\nParsing::\n\n    from drafthorse.models.document import Document\n    samplexml = open(\"sample.xml\", \"rb\").read()\n    doc = Document.parse(samplexml)\n    print(doc.trade.agreement.seller.name)\n\n``Document.parse()`` taskes a boolean parameter ``strict`` which defaults to ``True``. This means that the parser will raise an error if it encounters any unknown element. If you set it to ``False``, the parser will not raise an error and parse whatever it can.\n\nGenerating::\n\n    from datetime import date, datetime, timezone\n    from decimal import Decimal\n\n    from drafthorse.models.accounting import ApplicableTradeTax\n    from drafthorse.models.document import Document\n    from drafthorse.models.note import IncludedNote\n    from drafthorse.models.party import TaxRegistration\n    from drafthorse.models.tradelines import LineItem\n    from drafthorse.pdf import attach_xml\n\n    # Build data structure\n    doc = Document()\n    doc.context.guideline_parameter.id = \"urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended\"\n    doc.header.id = \"RE1337\"\n    doc.header.type_code = \"380\"\n    doc.header.name = \"RECHNUNG\"\n    doc.header.issue_date_time = date.today()\n    doc.header.languages.add(\"de\")\n\n    note = IncludedNote()\n    note.content.add(\"Test Node 1\")\n    doc.header.notes.add(note)\n\n    doc.trade.agreement.seller.name = \"Lieferant GmbH\"\n    doc.trade.settlement.payee.name = \"Lieferant GmbH\"\n\n    doc.trade.agreement.buyer.name = \"Kunde GmbH\"\n    doc.trade.settlement.invoicee.name = \"Kunde GmbH\"\n\n    doc.trade.settlement.currency_code = \"EUR\"\n    doc.trade.settlement.payment_means.type_code = \"ZZZ\"\n\n    doc.trade.agreement.seller.address.country_id = \"DE\"\n    doc.trade.agreement.seller.address.country_subdivision = \"Bayern\"\n    doc.trade.agreement.seller.tax_registrations.add(\n        TaxRegistration(\n            id=(\"VA\", \"DE000000000\")\n        )\n    )\n\n    doc.trade.agreement.seller_order.issue_date_time = datetime.now(timezone.utc)\n    doc.trade.agreement.buyer_order.issue_date_time = datetime.now(timezone.utc)\n    doc.trade.settlement.advance_payment.received_date = datetime.now(timezone.utc)\n    doc.trade.agreement.customer_order.issue_date_time = datetime.now(timezone.utc)\n\n    li = LineItem()\n    li.document.line_id = \"1\"\n    li.product.name = \"Rainbow\"\n    li.agreement.gross.amount = Decimal(\"999.00\")\n    li.agreement.gross.basis_quantity = (Decimal(\"1.0000\"), \"C62\")  # C62 == pieces\n    li.agreement.net.amount = Decimal(\"999.00\")\n    li.agreement.net.basis_quantity = (Decimal(\"999.00\"), \"EUR\")\n    li.delivery.billed_quantity = (Decimal(\"1.0000\"), \"C62\")  # C62 == pieces\n    li.settlement.trade_tax.type_code = \"VAT\"\n    li.settlement.trade_tax.category_code = \"E\"\n    li.settlement.trade_tax.rate_applicable_percent = Decimal(\"0.00\")\n    li.settlement.monetary_summation.total_amount = Decimal(\"999.00\")\n    doc.trade.items.add(li)\n\n    trade_tax = ApplicableTradeTax()\n    trade_tax.calculated_amount = Decimal(\"0.00\")\n    trade_tax.basis_amount = Decimal(\"999.00\")\n    trade_tax.type_code = \"VAT\"\n    trade_tax.category_code = \"AE\"\n    trade_tax.exemption_reason_code = 'VATEX-EU-AE'\n    trade_tax.rate_applicable_percent = Decimal(\"0.00\")\n    doc.trade.settlement.trade_tax.add(trade_tax)\n\n    doc.trade.settlement.monetary_summation.line_total = Decimal(\"999.00\")\n    doc.trade.settlement.monetary_summation.charge_total = Decimal(\"0.00\")\n    doc.trade.settlement.monetary_summation.allowance_total = Decimal(\"0.00\")\n    doc.trade.settlement.monetary_summation.tax_basis_total = Decimal(\"999.00\")\n    doc.trade.settlement.monetary_summation.tax_total = (Decimal(\"0.00\"), \"EUR\")\n    doc.trade.settlement.monetary_summation.grand_total = Decimal(\"999.00\")\n    doc.trade.settlement.monetary_summation.due_amount = Decimal(\"999.00\")\n\n    # Generate XML file\n    xml = doc.serialize(schema=\"FACTUR-X_EXTENDED\")\n\n    # Attach XML to an existing PDF.\n    # Note that the existing PDF should be compliant to PDF/A-3!\n    # You can validate this here: https://www.pdf-online.com/osa/validate.aspx\n    with open(\"input.pdf\", \"rb\") as original_file:\n        new_pdf_bytes = attach_xml(original_file.read(), xml)\n\n    with open(\"output.pdf\", \"wb\") as f:\n        f.write(new_pdf_bytes)\n\n``Document.serialize()`` will validate the generated XML against the specified schema and raise an error if it is not valid. If you want to avoid validation, you can set the ``schema`` parameter to ``None``.\n\nDevelopment\n-----------\n\nTo run the included tests::\n\n    pip install -r requirements_dev.txt\n    py.test tests\n\nTo automatically sort your Imports as required by CI::\n\n    pip install isort\n    isort -rc .\n\nTo validate files using mustang::\n\n    git clone https://github.com/ZUGFeRD/mustangproject.git\n    cd mustangproject\n    git checkout core-2.9.0\n    ./mvnw clean package\n    java -jar Mustang-CLI/target/Mustang-CLI-2.7.4-SNAPSHOT.jar --action validate --source invoice.pdf\n\n\nCredits and License\n-------------------\n\nMaintainer: Raphael Michel \u003cmichel@rami.io\u003e\n\nLicense of the Python code: Apache License 2.0\n\nThe PDF handling (drafthorse/pdf.py) was originally based on the code of factur-x, Copyright 2016-2018, Alexis de Lattre \u003calexis.delattre@akretion.com\u003e,\nreleased under a BSD license.\n\nThe 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpretix%2Fpython-drafthorse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpretix%2Fpython-drafthorse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpretix%2Fpython-drafthorse/lists"}