Skip to main content

django-xrechnung

PyPI version PyPI - Python Version PyPI - Django Versions from Framework Classifiers PyPI - License Latest on Django Packages

Need XRechnung or Factur-X invoices inside an existing Django project? Install this instead of implementing EN 16931 yourself.

You pass in buyer and line items. You get back an XRechnung or Factur-X XML file that has passed the official KoSIT validator, and a matching PDF, both stored on the invoice. Everything runs on your own server.

pip install django-xrechnung

From your order to a valid e-invoice

from datetime import date
from decimal import Decimal

from django_xrechnung.line_sources import SourceLine, materialize_lines
from django_xrechnung.services import create_invoice, finalize_invoice

invoice = create_invoice(              # seller, bank account and terms come from settings
    invoice_number="RE-2026-0142",
    invoice_date=date.today(),
    service_date=date.today(),
    buyer_name="Beispielverwaltung",
    buyer_street="Rathausstraße 2", buyer_postcode="28195", buyer_city="Bremen",
    buyer_endpoint="eingang@example.org",
    buyer_reference="04011000-12345-03",   # Leitweg-ID
)
materialize_lines(invoice, [
    SourceLine(description="Beratung", quantity=Decimal("2"), unit_code="HUR", unit_price=Decimal("50")),
    SourceLine(description="Fachbuch", unit_price=Decimal("100"), tax_rate=Decimal("7")),
], source_type="shop.Order")

invoice = finalize_invoice(invoice)    # validate with KoSIT, render XML + PDF, lock the invoice
invoice.xml, invoice.pdf               # stored files, ready to send or download

For Factur-X, add output_format="facturx_cii" to the create_invoice call. Use "facturx_hybrid" for a PDF/A-3 file with the XML embedded.

What comes out

This is the actual output of the code above. Files: invoice.pdf, xrechnung-ubl.xml, facturx-cii.xml.

PDF XRechnung XML (excerpt)
Generated PDF invoice RE-2026-0142 with two VAT rates
<Invoice ...>
  <cbc:CustomizationID>
    urn:cen.eu:en16931:2017#compliant
    #urn:xeinkauf.de:kosit:xrechnung_3.0
  </cbc:CustomizationID>
  <cbc:ID>RE-2026-0142</cbc:ID>
  <cbc:BuyerReference>
    04011000-12345-03
  </cbc:BuyerReference>
  <!-- seller, buyer, SEPA, terms … -->
  <cac:TaxTotal>
    <cbc:TaxAmount>26.00</cbc:TaxAmount>
    <cac:TaxSubtotal>
      <cbc:TaxableAmount>100.00</cbc:TaxableAmount>
      <cbc:TaxAmount>7.00</cbc:TaxAmount>
      <cac:TaxCategory>
        <cbc:ID>S</cbc:ID>
        <cbc:Percent>7.00</cbc:Percent>
      </cac:TaxCategory>
    </cac:TaxSubtotal>
    <!-- 19 % subtotal … -->
  </cac:TaxTotal>
  <cac:LegalMonetaryTotal>
    <cbc:TaxExclusiveAmount>200.00</cbc:TaxExclusiveAmount>
    <cbc:PayableAmount>226.00</cbc:PayableAmount>
  </cac:LegalMonetaryTotal>
  <!-- two InvoiceLine elements … -->
</Invoice>

Why not build it yourself?

The XML is the easy part. These are the parts that take the time:

  • Validation you can trust. Every invoice goes through the official KoSIT validator with pinned XRechnung 3.0.2 rules before it is issued. If it is rejected, nothing is stored and no invoice number is used up.
  • VAT arithmetic that matches the rules. Mixed rates, exemptions, reverse charge, intra-community supply and export, line discounts and surcharges, prepaid and rounding amounts. Totals are calculated with correct decimal rounding.
  • Immutable issued documents. Finalized invoices cannot be edited. XML, PDF, validation report and SHA-256 hashes are stored together. Corrections and credit notes refer back to the original invoice.
  • Gap-free numbering. Number series per seller are allocated inside the issuing transaction.
  • All the formats. XRechnung UBL, XRechnung CII, Factur-X EN 16931, and Factur-X PDF/A-3b hybrids that are checked with veraPDF.
  • Incoming invoices too. Receive XRechnung or Factur-X files, validate them safely, and review the parsed data in the admin.
  • Django-native. Admin screens, permissions, multiple sellers, JSON endpoints, signals before and after issuing, customizable PDF templates, and pluggable storage.

Get started

pip install django-xrechnung              # add [cii], [hybrid] or [inbound] as needed
python -m django_xrechnung.kosit /opt/kosit   # one-time download of the pinned validator
INSTALLED_APPS += ["django_xrechnung"]
DJANGO_XRECHNUNG = {
    "KOSIT_HOME": "/opt/kosit",
    "SELLER_DEFAULTS": {"supplier_name": "Example GmbH", ...},
}

Validation needs Java. PDF rendering uses WeasyPrint. The first-invoice tutorial takes you from installation to your first downloaded XML and PDF. The installation guide lists the system packages you need.

Scope

Beta (0.4.0), tested against real KoSIT acceptance and rejection. Outgoing invoices currently support German sellers and buyers and EUR. Electronic addresses can be an email address, a Leitweg-ID, a VAT ID or a GLN, and any UN/ECE unit code works. Payment can be by SEPA credit transfer, SEPA direct debit, or card. Document-level allowances and charges, other countries and currencies, and sending (Peppol, e-mail) are not supported yet. The supported invoice scenarios list the exact limits.

Documentation

django-xrechnung.readthedocs.io

There is also a runnable example project, along with the changelog and the contributing guide.

License

BSD 3-Clause. KoSIT, WeasyPrint and the system fonts keep their own upstream licenses.

Metadata

Release files for django-xrechnung 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-xrechnung 0.4.0
File Size Uploaded Provenance Actions
django_xrechnung-0.4.0.tar.gz 391.2 kB Without provenance Details for django_xrechnung-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-xrechnung 0.4.0
File Interpreter ABI Platform Actions
django_xrechnung-0.4.0-py3-none-any.whl Python 3 none any Details for django_xrechnung-0.4.0-py3-none-any.whl

Total release size: 602.5 kB

Release files / django_xrechnung-0.4.0.tar.gz

Download URL django_xrechnung-0.4.0.tar.gz
Size 391.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9897a731c6aabd16fc60de963f1a2c89c19010c769f235514181709ea16e74ff
BLAKE2b-256 checksum
How to use checksums
53db55be706bfd1b8583688bdd0a01cd0882aab354f07dc981a3266840d48cdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / django_xrechnung-0.4.0-py3-none-any.whl

Download URL django_xrechnung-0.4.0-py3-none-any.whl
Size 211.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55c9d6c5994bd5a46d053a513f5b8bc15c7035b6eec652690161234b6837d4b3
BLAKE2b-256 checksum
How to use checksums
41d03b9af91f664b17c1533d65f6eff78226464112bb877ee1e1914eb366e8df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for django-xrechnung 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page