Debian Codegraph @

PKG-INFO

raw
1 Metadata-Version: 2.1
2 Name: a38
3 Version: 0.1.8
4 Summary: parse and generate Italian Fattura Elettronica
5 Home-page: https://github.com/Truelite/python-a38/
6 Author: Enrico Zini
7 Author-email: [email protected]
8 License: https://www.apache.org/licenses/LICENSE-2.0.html
9 Requires-Python: >=3.11
10 Description-Content-Type: text/markdown
11 Provides-Extra: cacerts
12 Provides-Extra: formatted_python
13 Provides-Extra: html
14 License-File: LICENSE
15
16 # Python A38
17
18 ![full workflow](https://github.com/Truelite/python-a38/actions/workflows/py.yml/badge.svg)
19
20 Library to generate Italian Fattura Elettronica from Python.
21
22 This library implements a declarative data model similar to Django models, that
23 is designed to describe, validate, serialize and parse Italian Fattura
24 Elettronica data.
25
26 Only part of the specification is implemented, with more added as needs will
27 arise. You are welcome to implement the missing pieces you need and send a pull
28 request: the idea is to have a good, free (as in freedom) library to make
29 billing in Italy with Python easier for everyone.
30
31 The library can generate various kinds of fatture that pass validation, and can
32 parse all the example XML files distributed by
33 [fatturapa.gov.it](https://www.fatturapa.gov.it/it/lafatturapa/esempi/)
34
35
36 ## Dependencies
37
38 Required: dateutil, pytz, asn1crypto, and the python3 standard library.
39
40 Optional:
41 * yapf for formatting `a38tool python` output
42 * lxml for rendering to HTML
43 * the wkhtmltopdf command for rendering to PDF
44 * requests for downloading CA certificates for signature verification
45
46
47 ## `a38tool` script
48
49 A simple command line wrapper to the library functions is available as `a38tool`:
50
51 ```text
52 $ a38tool --help
53 usage: a38tool [-h] [--verbose] [--debug]
54 {json,xml,python,diff,validate,html,pdf,update_capath} ...
55
56 Handle fattura elettronica files
57
58 positional arguments:
59 {json,xml,python,diff,validate,html,pdf,update_capath}
60 actions
61 json output a fattura in JSON
62 xml output a fattura in XML
63 python output a fattura as Python code
64 diff show the difference between two fatture
65 validate validate the contents of a fattura
66 html render a Fattura as HTML using a .xslt stylesheet
67 pdf render a Fattura as PDF using a .xslt stylesheet
68 update_capath create/update an openssl CApath with CA certificates
69 that can be used to validate digital signatures
70
71 optional arguments:
72 -h, --help show this help message and exit
73 --verbose, -v verbose output
74 --debug debug output
75 ```
76
77 See [a38tool.md](a38tool.md) for more details.
78
79
80
81 ## Example code
82
83 ```py
84 import a38
85 from a38.validation import Validation
86 import datetime
87 import sys
88
89 cedente_prestatore = a38.CedentePrestatore(
90 a38.DatiAnagraficiCedentePrestatore(
91 a38.IdFiscaleIVA("IT", "01234567890"),
92 codice_fiscale="NTNBLN22C23A123U",
93 anagrafica=a38.Anagrafica(denominazione="Test User"),
94 regime_fiscale="RF01",
95 ),
96 a38.Sede(indirizzo="via Monferrato", numero_civico="1", cap="50100", comune="Firenze", provincia="FI", nazione="IT"),
97 iscrizione_rea=a38.IscrizioneREA(
98 ufficio="FI",
99 numero_rea="123456",
100 stato_liquidazione="LN",
101 ),
102 contatti=a38.Contatti(email="local_part@pec_domain.it"),
103 )
104
105 cessionario_committente = a38.CessionarioCommittente(
106 a38.DatiAnagraficiCessionarioCommittente(
107 a38.IdFiscaleIVA("IT", "76543210987"),
108 anagrafica=a38.Anagrafica(denominazione="A Company SRL"),
109 ),
110 a38.Sede(indirizzo="via Langhe", numero_civico="1", cap="50142", comune="Firenze", provincia="FI", nazione="IT"),
111 )
112
113 bill_number = 1
114
115 f = a38.FatturaPrivati12()
116 f.fattura_elettronica_header.dati_trasmissione.id_trasmittente = a38.IdTrasmittente("IT", "10293847561")
117 f.fattura_elettronica_header.dati_trasmissione.codice_destinatario = "FUFUFUF"
118 f.fattura_elettronica_header.cedente_prestatore = cedente_prestatore
119 f.fattura_elettronica_header.cessionario_committente = cessionario_committente
120
121 body = f.fattura_elettronica_body[0]
122 body.dati_generali.dati_generali_documento = a38.DatiGeneraliDocumento(
123 tipo_documento="TD01",
124 divisa="EUR",
125 data=datetime.date.today(),
126 numero=bill_number,
127 causale=["Test billing"],
128 )
129
130 body.dati_beni_servizi.add_dettaglio_linee(
131 descrizione="Test item", quantita=2, unita_misura="kg",
132 prezzo_unitario="25.50", aliquota_iva="22.00")
133
134 body.dati_beni_servizi.add_dettaglio_linee(
135 descrizione="Other item", quantita=1, unita_misura="kg",
136 prezzo_unitario="15.50", aliquota_iva="22.00")
137
138 body.dati_beni_servizi.build_dati_riepilogo()
139 body.build_importo_totale_documento()
140
141 res = Validation()
142 f.validate(res)
143 if res.warnings:
144 for w in res.warnings:
145 print(str(w), file=sys.stderr)
146 if res.errors:
147 for e in res.errors:
148 print(str(e), file=sys.stderr)
149
150 filename = "{}{}_{:05d}.xml".format(
151 f.fattura_elettronica_header.cedente_prestatore.dati_anagrafici.id_fiscale_iva.id_paese,
152 f.fattura_elettronica_header.cedente_prestatore.dati_anagrafici.id_fiscale_iva.id_codice,
153 bill_number)
154
155 tree = f.build_etree()
156 with open(filename, "wb") as out:
157 tree.write(out, encoding="utf-8", xml_declaration=True)
158 ```
159
160
161 # Digital signatures
162
163 Digital signatures on Firma Elettronica are
164 [CAdES](https://en.wikipedia.org/wiki/CAdES_(computing)) signatures.
165
166 openssl cal verify the signatures, but not yet generate them. A patch to sign
167 with CAdES [has been recently merged](https://github.com/openssl/openssl/commit/e85d19c68e7fb3302410bd72d434793e5c0c23a0)
168 but not yet released as of 2019-02-26.
169
170 ## Downloading CA certificates
171
172 CA certificates for validating digital certificates are
173 [distributed by the EU in XML format](https://ec.europa.eu/cefdigital/wiki/display/cefdigital/esignature).
174 See also [the AGID page about it](https://www.agid.gov.it/it/piattaforme/firma-elettronica-qualificata/certificati).
175
176 There is a [Trusted List Browser](https://webgate.ec.europa.eu/tl-browser/) but
177 apparently no way of getting a simple bundle of certificates useable by
178 openssl.
179
180 `a38tool` has basic features to download and parse CA certificate information,
181 and maintain a CA certificate directory:
182
183 ```
184 a38tool update_capath certdir/ --remove-old
185 ```
186
187 No particular effort is made to validate the downloaded certificates, besides
188 the standard HTTPS checks performed by the [requests
189 library](http://docs.python-requests.org/en/master/).
190
191 ## Verifying signed `.p7m` files
192
193 Once you have a CA certificate directory, verifying signed p7m files is quite
194 straightforward:
195
196 ```
197 openssl cms -verify -in tests/data/test.txt.p7m -inform der -CApath certs/
198 ```
199
200
201 # Useful links
202
203 XSLT stylesheets for displaying fatture:
204
205 * From [fatturapa.gov.it](https://www.fatturapa.gov.it/),
206 among the [FatturaPA resources](https://www.fatturapa.gov.it/it/norme-e-regole/documentazione-fattura-elettronica/formato-fatturapa/index.html)
207 * From [AssoSoftware](http://www.assosoftware.it/allegati/assoinvoice/FoglioStileAssoSoftware.zip)
208
209
210 # Copyright
211
212 Copyright 2019-2024 Truelite S.r.l.
213
214 This software is released under the Apache License 2.0