python_ubl
A pure Python library for generating and parsing UBL 2.1 XML documents with full PEPPOL BIS Billing 3.0 compliance.
Status: Alpha (v0.1.3)
This library is in early development. The API is not yet stable and may change in future releases.
Features
- Pure Python: No Django dependency required (optional Django integration available)
- UBL 2.1 Support: Generate and parse invoices and credit notes
- PEPPOL Compliance: Full support for PEPPOL BIS Billing 3.0
- Dataclass-based: Type-safe, immutable-by-convention data structures
- Bidirectional: Generate UBL XML from Python objects, parse UBL XML into Python objects
- Automatic Identifier Generation: Auto-generate PEPPOL participant identifiers from VAT/registration numbers
- 100 PEPPOL Schemes: Supports all PEPPOL v9.4 participant identifier schemes
Installation
pip install python_ubl
Quick Start
from ubl.models import Invoice, Party, InvoiceLine, Amount, Quantity, PostalAddress
from datetime import date
# Create a simple invoice
invoice = Invoice(
id="INV-001",
issue_date=date.today(),
supplier=Party(
name="My Company",
vat="BE0123456789",
country_code="BE",
postal_address=PostalAddress(
street_name="Main Street 1",
city_name="Brussels",
postal_zone="1000",
country="BE" # Smart casting: string -> Country object
)
),
customer=Party(...),
lines=[
InvoiceLine(
id="1",
invoiced_quantity=Quantity(value=10, unitCode="EA"),
line_extension_amount=Amount(value=100.00),
item=Item(name="Product A"),
price=Price(price_amount=Amount(value=10.00))
)
]
)
# Export to XML
xml_bytes = invoice.to_xml()
# Parse from XML
invoice = Invoice.from_xml(xml_bytes)
PEPPOL Compliance Mode
For PEPPOL BIS 3.0 / CEN EN16931 compliance, use the peppol_context() context manager:
from ubl import peppol_context
from ubl.models import Invoice
# Generate PEPPOL-compliant UBL XML
with peppol_context():
invoice = Invoice(...)
xml = invoice.to_xml_string()
When active, PEPPOL mode automatically:
- Removes forbidden elements: LineCountNumeric, TaxSubtotal/Percent, InvoiceLine/TaxTotal, FinancialInstitution
- Removes forbidden attributes: listID, schemeName, listAgencyID, unitCodeListID
- Filters identifiers: Uses only CEN-approved codes (0002-0240) for PartyIdentification
- Normalizes financial IDs: IBAN/BIC values are prefixed without schemeID attribute
- Simplifies tax schemes: Removes schemeID from PartyTaxScheme CompanyID (UBL-CR-652)
This ensures generated XML passes all CEN EN16931 and PEPPOL BIS 3.0 validation rules without manual adjustments.
Requirements
- Python 3.11+
- lxml >= 4.9.0
- python-dateutil >= 2.8.0
Development Status
Currently implemented:
- ✅ Basic components (Amount, Quantity, Identifier, Code)
- ✅ Aggregate components (Party, Address, Tax, Payment)
- ✅ PEPPOL identifier generation (100 schemes)
- ✅ Document models (Invoice, CreditNote)
- ✅ Bidirectional XML serialization
- ✅ Official UBL 2.1 example validation
Coming soon:
- 🚧 XSD schema validation
- 🚧 Business rules validation
- 🚧 Django integration module
- 🚧 Comprehensive documentation
- 🚧 Public repository and issue tracker
License
MIT License - see LICENSE file for details.
About
This library is developed by LevIT SC as part of their PEPPOL e-invoicing integration project.
Metadata
Release files for python-ubl 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_ubl-0.1.5.tar.gz | 52.6 kB | Without provenance | Details for python_ubl-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_ubl-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for python_ubl-0.1.5-py3-none-any.whl |
Total release size: 110.4 kB
Release files / python_ubl-0.1.5.tar.gz
| Download URL | python_ubl-0.1.5.tar.gz |
|---|---|
| Size | 52.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e0e7d9c57039f2bc5bd7054e27fd385be9555d0ad0848ce4295ea3f57a1b35a
|
|
BLAKE2b-256 checksum How to use checksums |
9858ead93d3fc768281d9e389f626903c8a670394ea8fc3da406218a29fa5d9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|
Release files / python_ubl-0.1.5-py3-none-any.whl
| Download URL | python_ubl-0.1.5-py3-none-any.whl |
|---|---|
| Size | 57.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7bd111d8aede6ab7216af222b585990a4e5c66e18a381685f0dba12e00ba87f3
|
|
BLAKE2b-256 checksum How to use checksums |
cce0e5280c5076ab58830f34090375e4c5813f72ac7e9bbab7a3454b16a4b4e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|
Security for python-ubl 0.1.5
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.