Skip to main content

Génération, validation et assemblage de factures électroniques Factur-X / EN 16931 en Python.

Project description

eFacturePy — ads-facturx

Génération, validation et assemblage de factures électroniques Factur-X / EN 16931 en Python.

Python Version Build Status


🧭 Sommaire


📖 À propos

eFacturePy est le dépôt de travail du package Python ads-facturx, un outil qui permet de :

  • produire un XML Cross Industry Invoice conforme au profil urn:cen.eu:en16931:2017 ;
  • générer le PDF/A-3 associé à l’aide de ReportLab ;
  • embarquer ce XML dans le PDF pour obtenir une Factur-X valide (via factur-x) ;
  • valider la facture via XSD (EN16931) et Schematron (moteur SaxonC-HE).

✨ Fonctionnalités

  • ✅ Génération d’un XML Factur-X / EN 16931 à partir d’un dict métier
  • ✅ Génération d’un PDF de facture (template par défaut + logo personnalisable)
  • ✅ Fusion PDF + XML → fichier Factur-X conforme
  • ✅ Validation XSD (profil en16931)
  • ✅ Validation Schematron via XSLT précompilé (SaxonC)
  • ✅ Modèles Pydantic v2 pour typer et valider les données métier

🏗️ Architecture du dépôt

eFacturePy/
├─ ads_facturx/              # Package distribué sur PyPI
│  ├─ Builders/              # Génération XML + PDF + Factur-X
│  ├─ Validators/            # XSD + Schematron (XSLT EN16931-CII)
│  ├─ models/                # Schémas Pydantic (DevisData, Invoice, …)
│  ├─ Samples/               # Jeu de données et XML de référence
│  └─ tests/                 # Tests unitaires pytest
├─ eFacturePy/               # Sorties d’exemple (PDF/XML générés)
├─ archive/                  # Ressources brutes : XSD, XSL, Schematron, Saxon
├─ dist/                     # Wheels et sdist historiques                   
├─ pyproject.toml            # Configuration Poetry
└─ poetry.lock

📦 Installation

Depuis PyPI :

pip install ads-facturx

Prérequis : Python ≥ 3.12. SaxonC-HE est installé automatiquement via la dépendance saxonche.


🚀 Démarrage rapide

Pipeline complet : validation → XML → contrôles XSD/Schematron → PDF → Factur-X.

from ads_facturx import (
    DevisData,
    export_xml, write_xml_from_string,
    xml_check_xsd, xml_check_schematron,
    export_pdf, generate_facturx,
)

# 1. Données métier (dict) → modèle validé
data = {...}                                      # voir docs/pdf/examples/sample_data.py
validated = DevisData.model_validate(data)

DESTINATION = "eFacturePy"
invoice_name = validated.invoice.name

# 2. XML EN 16931
xml_string = export_xml(validated)
xml_path   = write_xml_from_string(
    xml_string=xml_string,
    destination_folder=DESTINATION,
    file_name=invoice_name,
)

# 3. Validation XSD + Schematron
xml_check_xsd(xml_string)
report = xml_check_schematron(xml_path=xml_path)
print(report)

# 4. PDF (template par défaut)
export_pdf(
    title=invoice_name,
    output_path=f"{DESTINATION}/{invoice_name}.pdf",
    data=validated,
)

# 5. PDF + XML → Factur-X
generate_facturx(
    file_name=f"{invoice_name}.pdf",
    destination_folder=DESTINATION,
    xml=xml_string,
)

Un jeu de données complet, validable tel quel par DevisData, est fourni dans docs/pdf/examples/sample_data.py.


🔌 API publique

Exposée via from ads_facturx import ... (cf. ads_facturx/__init__.py).

Pipeline principal

Symbole Rôle
DevisData Modèle Pydantic v2 d'entrée (validation EN 16931).
export_xml(validated) Construit la chaîne XML CII profil en16931.
write_xml_from_string Sérialise l'XML sur disque (destination_folder, file_name).
xml_check_xsd Valide l'XML avec le XSD facturx / niveau en16931.
xml_check_schematron Applique les règles Schematron EN16931-CII via SaxonC.
export_pdf Génère le PDF de facture (ReportLab — template par défaut ou custom).
generate_facturx Embarque le XML dans le PDF pour produire la Factur-X finale.

Briques pour personnaliser le PDF (détails dans la doc PDF)

Template · ParagraphComponent · SpacerComponent · PageBreakComponent · BoxComponent · TableComponent · KeepInFrameComponent · DiyComponent · Header · Footer · TextElement · CenteredText · ImageElement · HorizontalLine · Theme · TableStyles · FontName · TableConfig · TableColumn · TableBox · ParagraphConfig · KeepInFrameConfig · FormatText · FormatDate · ExtraRow · ExtraRowCell · DocConfig · mm · A4 · colors.


🧾 Modèle de données

Schémas Pydantic v2 dans ads_facturx/models : DevisData (racine), Partner, Address, Invoice, InvoiceLine, InvoiceSummary, Footer, plus les énumérations normatives (CountryCode, CurrencyCode, UnitCode, VatCategory).

DevisData.model_validate(data) applique les contraintes EN 16931 critiques (formats de dates YYYYMMDD, codes pays/devise/unité, type TVA, …).

Détail des champs et exemple JSON complet : docs/pdf/03-input-data.md.


📚 Documentation détaillée

La génération PDF dispose de sa propre documentation, en 12 sections progressives :

docs/pdf/README.md — table des matières.

Au menu : quickstart, mental model, schéma DevisData, construction de templates, catalogue de composants, personnalisation (style / config), header & footer, composants DIY, défauts fournis, cookbook, erreurs courantes, référence API.

Tous les exemples sont exécutables :

python docs/pdf/examples/run_examples.py
# → PDFs écrits dans docs/pdf/examples/out/

✅ Validation EN 16931

  • XSD : xml_check_xsd s’appuie sur factur-x (flavor="facturx", level="en16931").
  • Schematron : xml_check_schematron exécute Validators/xslt/EN16931-CII-validation.xslt avec SaxonC et renvoie la liste des failed-assert (id, location, message).

📚 Dépendances

factur-x, saxonche, pydantic, reportlab (voir pyproject.toml et poetry.lock).

👤 Auteur

Antoine DucoulombierAlchimie Data Solutions · antoine.ducoulombier@alchimiedatasolutions.com

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

ads_facturx-0.7.0.tar.gz (170.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ads_facturx-0.7.0-py3-none-any.whl (182.7 kB view details)

Uploaded Python 3

File details

Details for the file ads_facturx-0.7.0.tar.gz.

File metadata

  • Download URL: ads_facturx-0.7.0.tar.gz
  • Upload date:
  • Size: 170.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.1 CPython/3.12.7 Windows/11

File hashes

Hashes for ads_facturx-0.7.0.tar.gz
Algorithm Hash digest
SHA256 e8fd3f547e10169438437183c2e815414f05882be136768ae208dbe0b5e42997
MD5 9e25dd75b00c4bac0165529f8b0f61c6
BLAKE2b-256 0ab2c359ebd4d3d15b5f57c7dd30276f06bc86f87d9a71ea7ae1bc7a7d81c9bf

See more details on using hashes here.

File details

Details for the file ads_facturx-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: ads_facturx-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 182.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.1 CPython/3.12.7 Windows/11

File hashes

Hashes for ads_facturx-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c00f25e21dc792a4d209f355871c3c20f408571c9ed36639a3259d41ae0304c
MD5 1b745da74227b950dd5d0c709c8ad1f2
BLAKE2b-256 bfa7e2874e2f67db3b34a4a8b2db0da9c528566cdf405fd535e39b511abc131b

See more details on using hashes here.

Supported by

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