Factur-X
raw JSON → 4.2 verified Fri May 01 auth: no python
A Python library for generating Factur-X (FR) and Order-X (DE) electronic invoices and orders in PDF/A-3 format with embedded XML. Current version 4.2, supports Python >=3.7. Release cadence is irregular.
pip install factur-x Common errors
error ModuleNotFoundError: No module named 'factur_x' ↓
cause Import uses hyphens in the package name, but Python packages cannot have hyphens. The correct import uses the canonical name without hyphen: `facturx`.
fix
Run
pip install factur-x (dash in pip), then import with from facturx import FacturX. error ValueError: Factur-X XML is not valid ↓
cause The XML file does not conform to the Factur-X schema (e.g., missing required fields, wrong namespaces).
fix
Check the XML against the official Factur-X specifications, particularly the namespace
urn:factur-x:pdfa:CrossIndustryDocument:1p0. error ImportError: cannot import name 'FacturX' from 'facturx' ↓
cause Possibly using a very old version (pre-4.0) where the class name was different or not exported.
fix
Upgrade to latest version:
pip install --upgrade factur-x. If still fails, check installed version with pip show factur-x. Warnings
breaking Version 4.0+ changed the API: removed the old `FacturX.generate()` without arguments. Now you must pass `xml_file` and `pdf_file`. ↓
fix Update calls to `FacturX(xml_file='...', pdf_file='...').generate()`
deprecated The `pyPdf` dependency is deprecated. Use `PyPDF2` or `pypdf` as a drop-in replacement. ↓
fix Replace `pip install factur-x` with `pip install factur-x[pdf]` for pypdf, or manually install `pypdf`.
gotcha The XML file must comply with the Factur-X standard (e.g., EN 16931). Non-compliant XML will raise validation errors. ↓
fix Validate your XML against the Factur-X schema before passing to the library.
Imports
- FacturX wrong
from factur_x import FacturXcorrectfrom facturx import FacturX - OrderX
from facturx import OrderX
Quickstart
from facturx import FacturX
# Create a Factur-X invoice
invoice = FacturX(
xml_file='invoice.xml',
pdf_file='output.pdf',
logo='logo.png', # optional
)
invoice.generate()
print('Invoice generated successfully')