facturx-api 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- facturx_api-0.1.0/LICENSE +21 -0
- facturx_api-0.1.0/PKG-INFO +148 -0
- facturx_api-0.1.0/README.md +129 -0
- facturx_api-0.1.0/pyproject.toml +43 -0
- facturx_api-0.1.0/setup.cfg +4 -0
- facturx_api-0.1.0/src/facturx_api/__init__.py +39 -0
- facturx_api-0.1.0/src/facturx_api/_client.py +354 -0
- facturx_api-0.1.0/src/facturx_api/_errors.py +155 -0
- facturx_api-0.1.0/src/facturx_api/_results.py +81 -0
- facturx_api-0.1.0/src/facturx_api/cli.py +129 -0
- facturx_api-0.1.0/src/facturx_api/py.typed +0 -0
- facturx_api-0.1.0/src/facturx_api.egg-info/PKG-INFO +148 -0
- facturx_api-0.1.0/src/facturx_api.egg-info/SOURCES.txt +16 -0
- facturx_api-0.1.0/src/facturx_api.egg-info/dependency_links.txt +1 -0
- facturx_api-0.1.0/src/facturx_api.egg-info/entry_points.txt +2 -0
- facturx_api-0.1.0/src/facturx_api.egg-info/top_level.txt +1 -0
- facturx_api-0.1.0/tests/test_cli.py +132 -0
- facturx_api-0.1.0/tests/test_client.py +286 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FacturX
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: facturx-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for the FacturX API: dry run, Factur-X PDF/A-3 conversion, validation.
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/facturxapi/sdk
|
|
7
|
+
Project-URL: Source, https://github.com/facturxapi/sdk/tree/main/python
|
|
8
|
+
Project-URL: Issues, https://github.com/facturxapi/sdk/issues
|
|
9
|
+
Keywords: factur-x,facturx,en16931,e-invoicing,facture-electronique
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Office/Business :: Financial :: Accounting
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# facturx-api (Python)
|
|
21
|
+
|
|
22
|
+
Client Python de FacturX API : simulation gratuite (`dry_run`), conversion finale en
|
|
23
|
+
Factur-X PDF/A-3 (ou XML CII), validation d'un fichier existant. Bibliothèque standard
|
|
24
|
+
uniquement, Python 3.10+.
|
|
25
|
+
|
|
26
|
+
> Statut 0.1.0 : **non publié sur PyPI.** Installation depuis la wheel construite localement.
|
|
27
|
+
> Parcours facture → fichiers exécuté contre staging le 06/11/2026 (voir « Ce qui est prouvé »).
|
|
28
|
+
|
|
29
|
+
## Installation (locale)
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
cd sdk/python && python -m build # produit dist/facturx_api-0.1.0-py3-none-any.whl
|
|
33
|
+
pip install dist/facturx_api-0.1.0-py3-none-any.whl
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Utilisation
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
import json
|
|
40
|
+
from facturx_api import FacturX
|
|
41
|
+
|
|
42
|
+
fx = FacturX(api_key="…", base_url="https://api.facturxapi.com")
|
|
43
|
+
invoice = json.load(open("invoice.json")) # JSON ERP complet
|
|
44
|
+
|
|
45
|
+
check = fx.dry_run(invoice) # gratuit, aucun livrable
|
|
46
|
+
if check.ready: # generationReadiness.status == "ready"
|
|
47
|
+
doc = fx.convert(invoice) # 1 facture traitée sur le quota
|
|
48
|
+
print(doc.save("out")) # out/factur-x.pdf et out/factur-x.xml
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Il n'y a **pas d'hôte par défaut** : `base_url` (ou `FACTURX_BASE_URL`) est obligatoire.
|
|
52
|
+
`api_key` peut venir de `FACTURX_API_KEY`.
|
|
53
|
+
|
|
54
|
+
- `ready` lit `generationReadiness.status`, pas `success` : une simulation peut répondre
|
|
55
|
+
`success=false` et autoriser quand même la génération.
|
|
56
|
+
- `convert` ne renvoie un résultat que si tous les champs de succès documentés sont au bon
|
|
57
|
+
état (`success`, `result.conversionSuccessful`, `target.status == verified`,
|
|
58
|
+
`finalGeneratedValidation`, packaging PDF/A-3). Sinon `NotDeliveredError.failed_checks`
|
|
59
|
+
dit lesquels : un HTTP 200 seul ne prouve rien.
|
|
60
|
+
- Si le PDF arrive par URL signée (`result.pdfUrl`), il est téléchargé **sans** la clé API.
|
|
61
|
+
|
|
62
|
+
Autres appels : `fx.validate(path_or_bytes, validation_target="en16931")`,
|
|
63
|
+
`fx.extract(pdf)` (XML embarqué d'un PDF Factur-X), `fx.meta()`, `fx.integration_contract()`
|
|
64
|
+
(ces deux derniers sans clé). Exemples exécutés : `sdk/examples/`.
|
|
65
|
+
|
|
66
|
+
## Ligne de commande `facturx`
|
|
67
|
+
|
|
68
|
+
Installée avec le paquet. Sortie JSON sur une ligne ; `FACTURX_API_KEY` et `FACTURX_BASE_URL`
|
|
69
|
+
(ou `--api-key`, `--base-url`).
|
|
70
|
+
|
|
71
|
+
| Commande | Effet | Code de sortie |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `facturx dry-run invoice.json` | simulation gratuite | 0 prêt, 1 non prêt |
|
|
74
|
+
| `facturx convert invoice.json --out DIR` | conversion finale, écrit `DIR/factur-x.pdf` et `.xml` | 0, ou 1 sans fichier vérifié |
|
|
75
|
+
| `facturx validate FICHIER [--target en16931]` | rapport de validation de l'API | 0 |
|
|
76
|
+
|
|
77
|
+
Codes communs : 2 argument ou fichier invalide, 3 erreur API (`code`, `api_message`,
|
|
78
|
+
`request_id` tels que l'API les envoie), 4 transport coupé (résultat inconnu : relancer avec
|
|
79
|
+
`--idempotency-key` égal à la clé affichée). Options `--target`, `--output`, `--idempotency-key`.
|
|
80
|
+
|
|
81
|
+
Exécution réelle contre staging (release `900685311ea7`, 06/11/2026 15:56Z, clé sandbox de test) :
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
$ facturx dry-run invoice.json
|
|
85
|
+
{"ok": true, "command": "dry-run", "ready": true, "generation_readiness": {"status": "ready", "blockingInputCount": 0, "reason": "no_generation_blocking_inputs"}, "request_id": "f0bb01da-564c-49ec-b4f0-2371f578773e", "idempotency_key": "b4aa1cc0-e675-4ffa-8ae6-644b111754f5"}
|
|
86
|
+
$ facturx convert invoice.json --out out-cli
|
|
87
|
+
{"ok": true, "command": "convert", "target": {"requested": "en16931", "executed": "en16931", "status": "verified", "missing_inputs": [], "not_run_reason": null}, "target_profile": "EN16931", "files": {"xml": {"path": "out-cli/factur-x.xml", "bytes": 4584, "sha256": "f332975e12f8dac94c926d8832c6434daf3ae718e3b10fb8acb9758bc940e03c"}, "pdf": {"path": "out-cli/factur-x.pdf", "bytes": 20624, "sha256": "75fd1d5e30ecf539a54ffc639134a17105b3b97e04941079c530cf2bb87ecd80"}}, "request_id": "66739ba5-e3c8-457b-9343-a90a9e836900", "idempotency_key": "df90c5ce-6b58-420d-a46b-4f72224b19e2"}
|
|
88
|
+
$ facturx validate out-cli/factur-x.pdf --target en16931 # extrait du rapport
|
|
89
|
+
ok= True | valid= True | validationStatus= valid | profile= EN16931 | target.status= verified | errors= 0
|
|
90
|
+
$ FACTURX_API_KEY=invalid facturx dry-run invoice.json # code de sortie 3
|
|
91
|
+
{"ok": false, "command": "dry-run", "error": {"type": "AuthenticationError", "message": "HTTP 401 invalid_api_key: The API key provided is invalid or revoked.", "status": 401, "code": "invalid_api_key", "request_id": "1c393ffb-981e-4bca-b148-57b8170a8240", "api_message": "The API key provided is invalid or revoked.", "idempotency_key": "42b47d9a-8ef4-4b22-90dd-17405957ffa2"}}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Erreurs
|
|
95
|
+
|
|
96
|
+
| Exception | Quand |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `AuthenticationError` | 401 / 403 |
|
|
99
|
+
| `QuotaExceededError` | 402 |
|
|
100
|
+
| `RateLimitError` | 429 |
|
|
101
|
+
| `InvalidRequestError` | 400 / 413 / 415 / 422 ; `issues` nomme les champs |
|
|
102
|
+
| `ConflictError` | 409 (idempotence, contexte) |
|
|
103
|
+
| `ServiceUnavailableError` / `ServerError` | 503 / autres 5xx |
|
|
104
|
+
| `ConversionPendingError` | 202 : traitement asynchrone, `job_id` |
|
|
105
|
+
| `NotDeliveredError` | 200 sans fichier final vérifié |
|
|
106
|
+
| `TransportError` | réseau coupé : **résultat inconnu** |
|
|
107
|
+
|
|
108
|
+
Toute `ApiError` porte `status`, `code` et `message` **tels que l'API les a envoyés**, plus
|
|
109
|
+
`request_id`, `issues`, `detail`, et `retryable` / `retry_after` seulement si le serveur les
|
|
110
|
+
a fournis (`None` sinon).
|
|
111
|
+
|
|
112
|
+
## Idempotence et reprise
|
|
113
|
+
|
|
114
|
+
Chaque appel `convert` / `dry_run` envoie un `Idempotency-Key` (UUID généré, ou le vôtre
|
|
115
|
+
via `idempotency_key=`). La clé est rendue sur le résultat **et** sur toute erreur. Pour
|
|
116
|
+
connaître l'issue d'une opération interrompue sans payer deux fois, renvoyez la même
|
|
117
|
+
requête avec la même clé : le corps envoyé est identique à l'octet près. Réutiliser une clé
|
|
118
|
+
avec une autre facture provoque `409 idempotency_conflict`.
|
|
119
|
+
|
|
120
|
+
**Le SDK ne relance jamais rien automatiquement.** La règle « un 5xx peut-il être renvoyé
|
|
121
|
+
tel quel » est en cours de fixation côté API (api#2111) ; tant qu'elle n'est pas publiée,
|
|
122
|
+
la décision reste à l'appelant.
|
|
123
|
+
|
|
124
|
+
## Ce qui est prouvé (06/11/2026)
|
|
125
|
+
|
|
126
|
+
- 24 tests hors réseau (`PYTHONPATH=src python -m unittest discover -s tests`), sockets interdits,
|
|
127
|
+
dont 8 pour la CLI et le rejeu de la conversion staging réelle (`tests/cassettes/` : réponses réelles réduites aux champs lus, PDF omis, XML réel).
|
|
128
|
+
- Parcours réel contre staging (release `900685311ea7`), clé sandbox de test, facture
|
|
129
|
+
`tests/fixtures/invoice.json`, même enchaînement que l’exemple « Utilisation », 06/11/2026 15:48Z :
|
|
130
|
+
|
|
131
|
+
```text
|
|
132
|
+
dry_run.ready = True | generationReadiness.status = ready | success = False | request_id = ea443cc8-30dd-4c17-b991-697d52f97646
|
|
133
|
+
convert: target = {"requested": "en16931", "executed": "en16931", "status": "verified", "missing_inputs": [], "not_run_reason": null} | profile = EN16931 | request_id = 2db8ddcb-8541-48e1-ae99-a1416221f6b3
|
|
134
|
+
pdf bytes = 20624 sha256 = dd9abd2cbab9679abdaf6e397fd0805032413a406bd757de23d009b4108f41f7 | starts b'%PDF-1.7'
|
|
135
|
+
xml bytes = 4584 sha256 = f332975e12f8dac94c926d8832c6434daf3ae718e3b10fb8acb9758bc940e03c
|
|
136
|
+
seconds command -> files = 21.426
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Le XML est identique, octet pour octet, à celui obtenu le 05/11 par `examples/first-file`
|
|
140
|
+
pour la même facture. PDF/A-3 et EN16931 sont attestés par l'API, pas revérifiés localement.
|
|
141
|
+
- Sans clé : `meta()`, `integration_contract()` et une clé invalide ⇒ `AuthenticationError`
|
|
142
|
+
401 `invalid_api_key` avec le message de l'API intact.
|
|
143
|
+
- `validate` : exécuté réellement via la CLI sur le PDF produit (voir « Ligne de commande »).
|
|
144
|
+
- `extract` : exécuté réellement, XML extrait identique au XML produit (`sdk/examples/extract-xml/run.txt`).
|
|
145
|
+
- `output="xml_cii"` : exécuté réellement pour EN16931 et EXTENDED (`sdk/examples/urn-par-profil/run.txt`).
|
|
146
|
+
|
|
147
|
+
**Pas encore prouvé avec ce SDK** : téléchargement par URL signée (`pdfUrl`), réponses 409/503
|
|
148
|
+
réelles (exercées hors ligne uniquement).
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# facturx-api (Python)
|
|
2
|
+
|
|
3
|
+
Client Python de FacturX API : simulation gratuite (`dry_run`), conversion finale en
|
|
4
|
+
Factur-X PDF/A-3 (ou XML CII), validation d'un fichier existant. Bibliothèque standard
|
|
5
|
+
uniquement, Python 3.10+.
|
|
6
|
+
|
|
7
|
+
> Statut 0.1.0 : **non publié sur PyPI.** Installation depuis la wheel construite localement.
|
|
8
|
+
> Parcours facture → fichiers exécuté contre staging le 06/11/2026 (voir « Ce qui est prouvé »).
|
|
9
|
+
|
|
10
|
+
## Installation (locale)
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
cd sdk/python && python -m build # produit dist/facturx_api-0.1.0-py3-none-any.whl
|
|
14
|
+
pip install dist/facturx_api-0.1.0-py3-none-any.whl
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Utilisation
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import json
|
|
21
|
+
from facturx_api import FacturX
|
|
22
|
+
|
|
23
|
+
fx = FacturX(api_key="…", base_url="https://api.facturxapi.com")
|
|
24
|
+
invoice = json.load(open("invoice.json")) # JSON ERP complet
|
|
25
|
+
|
|
26
|
+
check = fx.dry_run(invoice) # gratuit, aucun livrable
|
|
27
|
+
if check.ready: # generationReadiness.status == "ready"
|
|
28
|
+
doc = fx.convert(invoice) # 1 facture traitée sur le quota
|
|
29
|
+
print(doc.save("out")) # out/factur-x.pdf et out/factur-x.xml
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Il n'y a **pas d'hôte par défaut** : `base_url` (ou `FACTURX_BASE_URL`) est obligatoire.
|
|
33
|
+
`api_key` peut venir de `FACTURX_API_KEY`.
|
|
34
|
+
|
|
35
|
+
- `ready` lit `generationReadiness.status`, pas `success` : une simulation peut répondre
|
|
36
|
+
`success=false` et autoriser quand même la génération.
|
|
37
|
+
- `convert` ne renvoie un résultat que si tous les champs de succès documentés sont au bon
|
|
38
|
+
état (`success`, `result.conversionSuccessful`, `target.status == verified`,
|
|
39
|
+
`finalGeneratedValidation`, packaging PDF/A-3). Sinon `NotDeliveredError.failed_checks`
|
|
40
|
+
dit lesquels : un HTTP 200 seul ne prouve rien.
|
|
41
|
+
- Si le PDF arrive par URL signée (`result.pdfUrl`), il est téléchargé **sans** la clé API.
|
|
42
|
+
|
|
43
|
+
Autres appels : `fx.validate(path_or_bytes, validation_target="en16931")`,
|
|
44
|
+
`fx.extract(pdf)` (XML embarqué d'un PDF Factur-X), `fx.meta()`, `fx.integration_contract()`
|
|
45
|
+
(ces deux derniers sans clé). Exemples exécutés : `sdk/examples/`.
|
|
46
|
+
|
|
47
|
+
## Ligne de commande `facturx`
|
|
48
|
+
|
|
49
|
+
Installée avec le paquet. Sortie JSON sur une ligne ; `FACTURX_API_KEY` et `FACTURX_BASE_URL`
|
|
50
|
+
(ou `--api-key`, `--base-url`).
|
|
51
|
+
|
|
52
|
+
| Commande | Effet | Code de sortie |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| `facturx dry-run invoice.json` | simulation gratuite | 0 prêt, 1 non prêt |
|
|
55
|
+
| `facturx convert invoice.json --out DIR` | conversion finale, écrit `DIR/factur-x.pdf` et `.xml` | 0, ou 1 sans fichier vérifié |
|
|
56
|
+
| `facturx validate FICHIER [--target en16931]` | rapport de validation de l'API | 0 |
|
|
57
|
+
|
|
58
|
+
Codes communs : 2 argument ou fichier invalide, 3 erreur API (`code`, `api_message`,
|
|
59
|
+
`request_id` tels que l'API les envoie), 4 transport coupé (résultat inconnu : relancer avec
|
|
60
|
+
`--idempotency-key` égal à la clé affichée). Options `--target`, `--output`, `--idempotency-key`.
|
|
61
|
+
|
|
62
|
+
Exécution réelle contre staging (release `900685311ea7`, 06/11/2026 15:56Z, clé sandbox de test) :
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
$ facturx dry-run invoice.json
|
|
66
|
+
{"ok": true, "command": "dry-run", "ready": true, "generation_readiness": {"status": "ready", "blockingInputCount": 0, "reason": "no_generation_blocking_inputs"}, "request_id": "f0bb01da-564c-49ec-b4f0-2371f578773e", "idempotency_key": "b4aa1cc0-e675-4ffa-8ae6-644b111754f5"}
|
|
67
|
+
$ facturx convert invoice.json --out out-cli
|
|
68
|
+
{"ok": true, "command": "convert", "target": {"requested": "en16931", "executed": "en16931", "status": "verified", "missing_inputs": [], "not_run_reason": null}, "target_profile": "EN16931", "files": {"xml": {"path": "out-cli/factur-x.xml", "bytes": 4584, "sha256": "f332975e12f8dac94c926d8832c6434daf3ae718e3b10fb8acb9758bc940e03c"}, "pdf": {"path": "out-cli/factur-x.pdf", "bytes": 20624, "sha256": "75fd1d5e30ecf539a54ffc639134a17105b3b97e04941079c530cf2bb87ecd80"}}, "request_id": "66739ba5-e3c8-457b-9343-a90a9e836900", "idempotency_key": "df90c5ce-6b58-420d-a46b-4f72224b19e2"}
|
|
69
|
+
$ facturx validate out-cli/factur-x.pdf --target en16931 # extrait du rapport
|
|
70
|
+
ok= True | valid= True | validationStatus= valid | profile= EN16931 | target.status= verified | errors= 0
|
|
71
|
+
$ FACTURX_API_KEY=invalid facturx dry-run invoice.json # code de sortie 3
|
|
72
|
+
{"ok": false, "command": "dry-run", "error": {"type": "AuthenticationError", "message": "HTTP 401 invalid_api_key: The API key provided is invalid or revoked.", "status": 401, "code": "invalid_api_key", "request_id": "1c393ffb-981e-4bca-b148-57b8170a8240", "api_message": "The API key provided is invalid or revoked.", "idempotency_key": "42b47d9a-8ef4-4b22-90dd-17405957ffa2"}}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Erreurs
|
|
76
|
+
|
|
77
|
+
| Exception | Quand |
|
|
78
|
+
|---|---|
|
|
79
|
+
| `AuthenticationError` | 401 / 403 |
|
|
80
|
+
| `QuotaExceededError` | 402 |
|
|
81
|
+
| `RateLimitError` | 429 |
|
|
82
|
+
| `InvalidRequestError` | 400 / 413 / 415 / 422 ; `issues` nomme les champs |
|
|
83
|
+
| `ConflictError` | 409 (idempotence, contexte) |
|
|
84
|
+
| `ServiceUnavailableError` / `ServerError` | 503 / autres 5xx |
|
|
85
|
+
| `ConversionPendingError` | 202 : traitement asynchrone, `job_id` |
|
|
86
|
+
| `NotDeliveredError` | 200 sans fichier final vérifié |
|
|
87
|
+
| `TransportError` | réseau coupé : **résultat inconnu** |
|
|
88
|
+
|
|
89
|
+
Toute `ApiError` porte `status`, `code` et `message` **tels que l'API les a envoyés**, plus
|
|
90
|
+
`request_id`, `issues`, `detail`, et `retryable` / `retry_after` seulement si le serveur les
|
|
91
|
+
a fournis (`None` sinon).
|
|
92
|
+
|
|
93
|
+
## Idempotence et reprise
|
|
94
|
+
|
|
95
|
+
Chaque appel `convert` / `dry_run` envoie un `Idempotency-Key` (UUID généré, ou le vôtre
|
|
96
|
+
via `idempotency_key=`). La clé est rendue sur le résultat **et** sur toute erreur. Pour
|
|
97
|
+
connaître l'issue d'une opération interrompue sans payer deux fois, renvoyez la même
|
|
98
|
+
requête avec la même clé : le corps envoyé est identique à l'octet près. Réutiliser une clé
|
|
99
|
+
avec une autre facture provoque `409 idempotency_conflict`.
|
|
100
|
+
|
|
101
|
+
**Le SDK ne relance jamais rien automatiquement.** La règle « un 5xx peut-il être renvoyé
|
|
102
|
+
tel quel » est en cours de fixation côté API (api#2111) ; tant qu'elle n'est pas publiée,
|
|
103
|
+
la décision reste à l'appelant.
|
|
104
|
+
|
|
105
|
+
## Ce qui est prouvé (06/11/2026)
|
|
106
|
+
|
|
107
|
+
- 24 tests hors réseau (`PYTHONPATH=src python -m unittest discover -s tests`), sockets interdits,
|
|
108
|
+
dont 8 pour la CLI et le rejeu de la conversion staging réelle (`tests/cassettes/` : réponses réelles réduites aux champs lus, PDF omis, XML réel).
|
|
109
|
+
- Parcours réel contre staging (release `900685311ea7`), clé sandbox de test, facture
|
|
110
|
+
`tests/fixtures/invoice.json`, même enchaînement que l’exemple « Utilisation », 06/11/2026 15:48Z :
|
|
111
|
+
|
|
112
|
+
```text
|
|
113
|
+
dry_run.ready = True | generationReadiness.status = ready | success = False | request_id = ea443cc8-30dd-4c17-b991-697d52f97646
|
|
114
|
+
convert: target = {"requested": "en16931", "executed": "en16931", "status": "verified", "missing_inputs": [], "not_run_reason": null} | profile = EN16931 | request_id = 2db8ddcb-8541-48e1-ae99-a1416221f6b3
|
|
115
|
+
pdf bytes = 20624 sha256 = dd9abd2cbab9679abdaf6e397fd0805032413a406bd757de23d009b4108f41f7 | starts b'%PDF-1.7'
|
|
116
|
+
xml bytes = 4584 sha256 = f332975e12f8dac94c926d8832c6434daf3ae718e3b10fb8acb9758bc940e03c
|
|
117
|
+
seconds command -> files = 21.426
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Le XML est identique, octet pour octet, à celui obtenu le 05/11 par `examples/first-file`
|
|
121
|
+
pour la même facture. PDF/A-3 et EN16931 sont attestés par l'API, pas revérifiés localement.
|
|
122
|
+
- Sans clé : `meta()`, `integration_contract()` et une clé invalide ⇒ `AuthenticationError`
|
|
123
|
+
401 `invalid_api_key` avec le message de l'API intact.
|
|
124
|
+
- `validate` : exécuté réellement via la CLI sur le PDF produit (voir « Ligne de commande »).
|
|
125
|
+
- `extract` : exécuté réellement, XML extrait identique au XML produit (`sdk/examples/extract-xml/run.txt`).
|
|
126
|
+
- `output="xml_cii"` : exécuté réellement pour EN16931 et EXTENDED (`sdk/examples/urn-par-profil/run.txt`).
|
|
127
|
+
|
|
128
|
+
**Pas encore prouvé avec ce SDK** : téléchargement par URL signée (`pdfUrl`), réponses 409/503
|
|
129
|
+
réelles (exercées hors ligne uniquement).
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "facturx-api"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python client for the FacturX API: dry run, Factur-X PDF/A-3 conversion, validation."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
dependencies = []
|
|
12
|
+
license = {text = "MIT"}
|
|
13
|
+
keywords = ["factur-x", "facturx", "en16931", "e-invoicing", "facture-electronique"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Topic :: Office/Business :: Financial :: Accounting",
|
|
19
|
+
"Typing :: Typed",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
facturx = "facturx_api.cli:main"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/facturxapi/sdk"
|
|
28
|
+
Source = "https://github.com/facturxapi/sdk/tree/main/python"
|
|
29
|
+
Issues = "https://github.com/facturxapi/sdk/issues"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools.packages.find]
|
|
32
|
+
where = ["src"]
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.package-data]
|
|
35
|
+
facturx_api = ["py.typed"]
|
|
36
|
+
|
|
37
|
+
[tool.ruff]
|
|
38
|
+
line-length = 100
|
|
39
|
+
target-version = "py310"
|
|
40
|
+
|
|
41
|
+
[tool.ruff.lint]
|
|
42
|
+
select = ["E", "W", "F", "I", "B", "C4", "UP"]
|
|
43
|
+
ignore = ["E501"]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""FacturX API Python SDK (standard library only)."""
|
|
2
|
+
|
|
3
|
+
from ._client import FacturX, Transport, __version__, urllib_transport
|
|
4
|
+
from ._errors import (
|
|
5
|
+
ApiError,
|
|
6
|
+
AuthenticationError,
|
|
7
|
+
ConflictError,
|
|
8
|
+
ConversionPendingError,
|
|
9
|
+
FacturXError,
|
|
10
|
+
InvalidRequestError,
|
|
11
|
+
NotDeliveredError,
|
|
12
|
+
QuotaExceededError,
|
|
13
|
+
RateLimitError,
|
|
14
|
+
ServerError,
|
|
15
|
+
ServiceUnavailableError,
|
|
16
|
+
TransportError,
|
|
17
|
+
)
|
|
18
|
+
from ._results import ConvertResult, DryRunResult
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"ApiError",
|
|
22
|
+
"AuthenticationError",
|
|
23
|
+
"ConflictError",
|
|
24
|
+
"ConversionPendingError",
|
|
25
|
+
"ConvertResult",
|
|
26
|
+
"DryRunResult",
|
|
27
|
+
"FacturX",
|
|
28
|
+
"FacturXError",
|
|
29
|
+
"InvalidRequestError",
|
|
30
|
+
"NotDeliveredError",
|
|
31
|
+
"QuotaExceededError",
|
|
32
|
+
"RateLimitError",
|
|
33
|
+
"ServerError",
|
|
34
|
+
"ServiceUnavailableError",
|
|
35
|
+
"Transport",
|
|
36
|
+
"TransportError",
|
|
37
|
+
"__version__",
|
|
38
|
+
"urllib_transport",
|
|
39
|
+
]
|