Skip to main content

fatturapa

PyPI Python Licenza MIT

Parser della Fattura Elettronica italiana — tracciato FatturaPA v1.2, formati FPR12 e FPA12. Zero dipendenze: solo standard library.

Parser for the Italian electronic invoice format (FatturaPA v1.2). Turns the XML into plain dataclasses. No dependencies.

Trasforma l'XML in dataclass già leggibili — codici decodificati, importi e date all'italiana — pronte da impaginare come preferisci. La libreria non genera PDF e non impone un motore di template: la resa grafica resta tua.

pip install fatturapa
from fatturapa import parse

for documento in parse(xml_bytes):
    print(documento.tipo_documento, documento.numero, documento.data)
    print(documento.cessionario.denominazione)
    for linea in documento.linee:
        print(" ", linea.descrizione, linea.quantita, linea.prezzo_totale)
    print("Totale:", documento.importo_totale, documento.divisa)
Fattura 123 18/12/2014
DITTA BETA
  DESCRIZIONE DELLA FORNITURA 5 5,00
Totale: 6,10 EUR

Cosa fa (e cosa no)

Legge il tracciato e te lo restituisce in una forma comoda da stampare:

  • decodifica i codici — TD01 → Fattura, RF19 → Forfettario, MP05 → Bonifico, e così per Natura, CondizioniPagamento, EsigibilitaIVA;
  • formatta all'italiana — 1234.56 → 1.234,56, 2026-01-20 → 20/01/2026;
  • calcola i totali dai riepiloghi, e ricava il totale documento (imponibile + imposta + bollo) quando ImportoTotaleDocumento manca, visto che è opzionale.

Non valida contro l'XSD, non verifica firme digitali, non estrae allegati. Se ti serve quello, guarda fattura-elettronica-reader.

Scelte di fondo

  • Namespace-agnostico. L'XML del SdI mescola il namespace del tracciato, figli con xmlns="" e una firma XAdES innestata; la navigazione avviene per nome locale del tag, quindi funziona con o senza prefisso.
  • Nessuna eccezione sui campi opzionali. I tag mancanti diventano stringhe o liste vuote: mai None. Il codice che stampa non deve difendersi.
  • Le fatture in lotto sono la norma. Una FatturaElettronica può contenere più FatturaElettronicaBody: parse() restituisce sempre una list[Documento].

parse() solleva ValueError solo se la radice non è <FatturaElettronica>, se l'XML è malformato o se non c'è alcun corpo documento. Per un controllo preventivo che non solleva mai c'è is_fattura(raw):

from fatturapa import is_fattura

if is_fattura(contenuto):
    documenti = parse(contenuto)

Il modello

parse() restituisce una lista di Documento:

campo contenuto
tipo_documento / tipo_documento_codice Fattura / TD01
numero, data, divisa, causali dati generali
importo_totale, totale_imponibile, totale_imposta, bollo totali
cedente, cessionario Soggetto (denominazione, partita_iva, sede, indirizzo_completo)
linee list[Linea] (descrizione, quantità, prezzi, aliquota, codice_articolo)
riepiloghi list[Riepilogo] (aliquota, natura, imponibile, imposta, riferimento normativo)
pagamenti, condizioni_pagamento list[Pagamento] (modalità, scadenza, IBAN, istituto)
trasporto Trasporto (causale, colli, peso, indirizzo_resa)
ordini list[DatiOrdine] (DatiOrdineAcquisto)

Tutti i valori sono stringhe già formattate per essere stampate. Se ti servono come numeri, riconvertili tu: la libreria non fa scelte al posto tuo su arrotondamenti e valuta.

Un .p7m firmato?

Le fatture arrivano spesso firmate (.xml.p7m). Estrai prima il contenuto, poi passalo a parse():

openssl smime -verify -in fattura.xml.p7m -inform DER -noverify -out fattura.xml

Per farlo da interfaccia web c'è p7m-apri, che usa questa stessa libreria per visualizzare le fatture.

Sviluppo

poetry install
poetry run pytest
poetry run ruff check .

I test girano sui tracciati di esempio pubblicati dall'Agenzia delle Entrate (in tests/tracciati/), più casi mirati costruiti a mano per trasporto, bollo, natura e formattazione.

Licenza MIT.

Metadata

Release files for fatturapa 0.2.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 fatturapa 0.2.0
File Size Uploaded Provenance
fatturapa-0.2.0.tar.gz 12.0 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fatturapa 0.2.0
File Interpreter ABI Platform
fatturapa-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / fatturapa-0.2.0.tar.gz

Download URL fatturapa-0.2.0.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5507d6e6f96799067f09864f5e139246498570586ce4a7b4e1f70480bc600db8
BLAKE2b-256 checksum
How to use checksums
7fed8889456cd119c8a7d6208603079d9c40cfdd9da341536c2131a5a129f69c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release files / fatturapa-0.2.0-py3-none-any.whl

Download URL fatturapa-0.2.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ad63dd1f7a8d0c7e362699ee99019fd00c3917de74e237c6a70515efea820cb
BLAKE2b-256 checksum
How to use checksums
801dbc8dd45abbad1374cffbe7755280c4c7b7f4e8cef8440cf46cc407896e55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Security for fatturapa 0.2.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fatturapa-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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