efact 1.0.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.
Files changed (37) hide show
  1. efact-1.0.0/LICENSE +21 -0
  2. efact-1.0.0/PKG-INFO +173 -0
  3. efact-1.0.0/README.md +151 -0
  4. efact-1.0.0/efact/__init__.py +61 -0
  5. efact-1.0.0/efact/_generated/__init__.py +44 -0
  6. efact-1.0.0/efact/_generated/api/__init__.py +5 -0
  7. efact-1.0.0/efact/_generated/api/invoices_api.py +1747 -0
  8. efact-1.0.0/efact/_generated/api_client.py +798 -0
  9. efact-1.0.0/efact/_generated/api_response.py +21 -0
  10. efact-1.0.0/efact/_generated/configuration.py +575 -0
  11. efact-1.0.0/efact/_generated/exceptions.py +200 -0
  12. efact-1.0.0/efact/_generated/models/__init__.py +27 -0
  13. efact-1.0.0/efact/_generated/models/api_response_invoice_response.py +106 -0
  14. efact-1.0.0/efact/_generated/models/api_response_invoice_status_response.py +106 -0
  15. efact-1.0.0/efact/_generated/models/api_response_page_response_invoice_response.py +106 -0
  16. efact-1.0.0/efact/_generated/models/create_invoice_line_request.py +99 -0
  17. efact-1.0.0/efact/_generated/models/create_invoice_request.py +145 -0
  18. efact-1.0.0/efact/_generated/models/field_error.py +90 -0
  19. efact-1.0.0/efact/_generated/models/invoice_response.py +161 -0
  20. efact-1.0.0/efact/_generated/models/invoice_status_response.py +115 -0
  21. efact-1.0.0/efact/_generated/models/page_response_invoice_response.py +108 -0
  22. efact-1.0.0/efact/_generated/models/update_invoice_request.py +166 -0
  23. efact-1.0.0/efact/_generated/rest.py +258 -0
  24. efact-1.0.0/efact/client.py +117 -0
  25. efact-1.0.0/efact/errors.py +123 -0
  26. efact-1.0.0/efact/invoices.py +91 -0
  27. efact-1.0.0/efact/runtime.py +144 -0
  28. efact-1.0.0/efact.egg-info/PKG-INFO +173 -0
  29. efact-1.0.0/efact.egg-info/SOURCES.txt +35 -0
  30. efact-1.0.0/efact.egg-info/dependency_links.txt +1 -0
  31. efact-1.0.0/efact.egg-info/requires.txt +9 -0
  32. efact-1.0.0/efact.egg-info/top_level.txt +1 -0
  33. efact-1.0.0/pyproject.toml +32 -0
  34. efact-1.0.0/setup.cfg +4 -0
  35. efact-1.0.0/tests/test_client.py +77 -0
  36. efact-1.0.0/tests/test_invoices.py +93 -0
  37. efact-1.0.0/tests/test_runtime.py +144 -0
efact-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Itzenata
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.
efact-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,173 @@
1
+ Metadata-Version: 2.4
2
+ Name: efact
3
+ Version: 1.0.0
4
+ Summary: SDK Python officiel EFact pour l'e-facturation (DGI Maroc)
5
+ Author-email: Itzenata <contact@itzenata.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/itzenata/sdk/tree/main/python-sdk#readme
8
+ Project-URL: Repository, https://github.com/itzenata/sdk
9
+ Keywords: efact,e-facturation,invoice,invoicing,dgi,morocco,maroc,itzenata,sdk
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: urllib3<3,>=1.25.3
14
+ Requires-Dist: python-dateutil>=2.8.2
15
+ Requires-Dist: pydantic>=2
16
+ Requires-Dist: typing-extensions>=4.7.1
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=8; extra == "dev"
19
+ Requires-Dist: build; extra == "dev"
20
+ Requires-Dist: twine; extra == "dev"
21
+ Dynamic: license-file
22
+
23
+ # efact
24
+
25
+ SDK Python officiel **EFact** pour l'e-facturation au Maroc (mandat DGI).
26
+
27
+ EFact est une API de conformité (« le Stripe de la facturation électronique »).
28
+ Ce SDK est une fine couche typée au-dessus de l'API REST EFact :
29
+ authentification par clé, nouveaux essais, délais, et erreurs typées.
30
+
31
+ - ✅ Typé (Pydantic v2)
32
+ - ✅ Timeouts, retries avec back-off, erreurs typées
33
+ - ✅ Généré depuis le contrat OpenAPI — toujours aligné sur l'API
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ pip install efact
39
+ ```
40
+
41
+ Prérequis : **Python ≥ 3.9**.
42
+
43
+ ## Démarrage rapide
44
+
45
+ ```python
46
+ import os
47
+ from efact import EFact
48
+
49
+ # La clé secrète identifie ET authentifie votre organisation (modèle Stripe).
50
+ # Ne la committez jamais : chargez-la depuis l'environnement.
51
+ efact = EFact(os.environ["EFACT_SECRET_KEY"])
52
+
53
+ invoice = efact.invoices.create({
54
+ "invoiceNumber": "INV-2026-001",
55
+ "invoiceDate": "2026-06-24",
56
+ "currency": "MAD",
57
+ "paymentMethod": "BANK_TRANSFER",
58
+ # Acheteur (optionnel) — format plat, aligné sur l'API.
59
+ "buyerIce": "001234567890123", # 15 chiffres si fourni
60
+ "buyerName": "Client SARL",
61
+ "buyerAddress": "Casablanca",
62
+ "lines": [
63
+ {
64
+ "lineNumber": 1,
65
+ "description": "Prestation de service",
66
+ "quantity": 1,
67
+ "unitPrice": 1000,
68
+ "vatRate": 20,
69
+ },
70
+ ],
71
+ })
72
+
73
+ print(invoice.id, invoice.status)
74
+ ```
75
+
76
+ ## Configuration
77
+
78
+ **Aucune configuration n'est requise.** `EFact(secret_key)` cible la production
79
+ et gère l'authentification, l'URL, les délais et les nouveaux essais pour vous.
80
+
81
+ Deux options facultatives permettent d'ajuster le comportement réseau (valeurs
82
+ par défaut sûres) :
83
+
84
+ ```python
85
+ EFact(
86
+ secret_key,
87
+ timeout=30.0, # délai max par requête (s) — défaut 30
88
+ max_retries=2, # rejeux sur erreurs transitoires (méthodes sûres) — défaut 2
89
+ )
90
+ ```
91
+
92
+ ## Opérations sur les factures
93
+
94
+ | Méthode | Description |
95
+ | --- | --- |
96
+ | `efact.invoices.create(data)` | Crée une facture |
97
+ | `efact.invoices.list(...)` | Liste paginée (filtre par statut optionnel) |
98
+ | `efact.invoices.retrieve(id)` | Récupère une facture |
99
+ | `efact.invoices.retrieve_status(id)` | Statut de clairance DGI |
100
+ | `efact.invoices.update(id, patch)` | Met à jour une facture (PENDING uniquement) |
101
+ | `efact.invoices.cancel(id)` | Annule une facture (PENDING uniquement) |
102
+
103
+ L'organisation est résolue côté serveur à partir de la clé API : aucun
104
+ `organization_id` n'est transmis. La modification et l'annulation ne sont
105
+ possibles que tant que la facture est au statut `PENDING`.
106
+
107
+ ```python
108
+ # Lister (pagination + filtre optionnels)
109
+ page = efact.invoices.list(page=0, size=20, status="ACCEPTED")
110
+ for inv in page.content:
111
+ print(inv.invoice_number, inv.status)
112
+
113
+ # Suivre la clairance DGI
114
+ status = efact.invoices.retrieve_status(invoice.id)
115
+ print(status.status, status.dgi_reference)
116
+ ```
117
+
118
+ ## Gestion des erreurs
119
+
120
+ Toutes les erreurs héritent de `EFactError`. Les réponses non-OK de l'API
121
+ sont converties en erreurs typées portant `code`, `http_status` et `errors`.
122
+
123
+ ```python
124
+ from efact import (
125
+ EFactApiError,
126
+ EFactAuthError,
127
+ EFactValidationError,
128
+ EFactNotFoundError,
129
+ EFactConflictError,
130
+ EFactConnectionError,
131
+ EFactTimeoutError,
132
+ )
133
+
134
+ try:
135
+ efact.invoices.create(data)
136
+ except EFactValidationError as e:
137
+ print("Champs invalides :", e.errors)
138
+ except EFactAuthError:
139
+ print("Clé API manquante ou invalide.")
140
+ except EFactConflictError:
141
+ print("Facture non modifiable (statut ≠ PENDING).")
142
+ except EFactApiError as e:
143
+ print(e.code, e.http_status, e)
144
+ except EFactTimeoutError:
145
+ print("Délai dépassé.")
146
+ except EFactConnectionError:
147
+ print("Échec réseau.")
148
+ ```
149
+
150
+ | Erreur | Cas |
151
+ | --- | --- |
152
+ | `EFactConfigError` | Mauvaise configuration (avant tout appel réseau) |
153
+ | `EFactAuthError` | 401/403 — clé manquante/invalide |
154
+ | `EFactValidationError` | 400/422 — champs invalides (`errors`) |
155
+ | `EFactNotFoundError` | 404 — introuvable (inclut cross-tenant) |
156
+ | `EFactConflictError` | 409 — facture non modifiable/annulable |
157
+ | `EFactApiError` | autre erreur API |
158
+ | `EFactTimeoutError` | délai dépassé |
159
+ | `EFactConnectionError` | échec réseau |
160
+
161
+ Les méthodes sûres (`GET`/`PUT`/`DELETE`) sont automatiquement rejouées sur
162
+ les erreurs transitoires (408, 425, 429, 5xx, coupures réseau) avec back-off
163
+ exponentiel et respect de `Retry-After`. `POST` (création) n'est jamais rejoué.
164
+
165
+ ## Sécurité
166
+
167
+ - La clé n'est attachée qu'en `Authorization: Bearer <clé>`, jamais dans l'URL.
168
+ - `efact.get_config()` ne renvoie qu'une version masquée de la clé.
169
+ - Les messages d'erreur n'incluent jamais la clé ni le corps brut de la réponse.
170
+
171
+ ## Licence
172
+
173
+ [MIT](./LICENSE)
efact-1.0.0/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # efact
2
+
3
+ SDK Python officiel **EFact** pour l'e-facturation au Maroc (mandat DGI).
4
+
5
+ EFact est une API de conformité (« le Stripe de la facturation électronique »).
6
+ Ce SDK est une fine couche typée au-dessus de l'API REST EFact :
7
+ authentification par clé, nouveaux essais, délais, et erreurs typées.
8
+
9
+ - ✅ Typé (Pydantic v2)
10
+ - ✅ Timeouts, retries avec back-off, erreurs typées
11
+ - ✅ Généré depuis le contrat OpenAPI — toujours aligné sur l'API
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pip install efact
17
+ ```
18
+
19
+ Prérequis : **Python ≥ 3.9**.
20
+
21
+ ## Démarrage rapide
22
+
23
+ ```python
24
+ import os
25
+ from efact import EFact
26
+
27
+ # La clé secrète identifie ET authentifie votre organisation (modèle Stripe).
28
+ # Ne la committez jamais : chargez-la depuis l'environnement.
29
+ efact = EFact(os.environ["EFACT_SECRET_KEY"])
30
+
31
+ invoice = efact.invoices.create({
32
+ "invoiceNumber": "INV-2026-001",
33
+ "invoiceDate": "2026-06-24",
34
+ "currency": "MAD",
35
+ "paymentMethod": "BANK_TRANSFER",
36
+ # Acheteur (optionnel) — format plat, aligné sur l'API.
37
+ "buyerIce": "001234567890123", # 15 chiffres si fourni
38
+ "buyerName": "Client SARL",
39
+ "buyerAddress": "Casablanca",
40
+ "lines": [
41
+ {
42
+ "lineNumber": 1,
43
+ "description": "Prestation de service",
44
+ "quantity": 1,
45
+ "unitPrice": 1000,
46
+ "vatRate": 20,
47
+ },
48
+ ],
49
+ })
50
+
51
+ print(invoice.id, invoice.status)
52
+ ```
53
+
54
+ ## Configuration
55
+
56
+ **Aucune configuration n'est requise.** `EFact(secret_key)` cible la production
57
+ et gère l'authentification, l'URL, les délais et les nouveaux essais pour vous.
58
+
59
+ Deux options facultatives permettent d'ajuster le comportement réseau (valeurs
60
+ par défaut sûres) :
61
+
62
+ ```python
63
+ EFact(
64
+ secret_key,
65
+ timeout=30.0, # délai max par requête (s) — défaut 30
66
+ max_retries=2, # rejeux sur erreurs transitoires (méthodes sûres) — défaut 2
67
+ )
68
+ ```
69
+
70
+ ## Opérations sur les factures
71
+
72
+ | Méthode | Description |
73
+ | --- | --- |
74
+ | `efact.invoices.create(data)` | Crée une facture |
75
+ | `efact.invoices.list(...)` | Liste paginée (filtre par statut optionnel) |
76
+ | `efact.invoices.retrieve(id)` | Récupère une facture |
77
+ | `efact.invoices.retrieve_status(id)` | Statut de clairance DGI |
78
+ | `efact.invoices.update(id, patch)` | Met à jour une facture (PENDING uniquement) |
79
+ | `efact.invoices.cancel(id)` | Annule une facture (PENDING uniquement) |
80
+
81
+ L'organisation est résolue côté serveur à partir de la clé API : aucun
82
+ `organization_id` n'est transmis. La modification et l'annulation ne sont
83
+ possibles que tant que la facture est au statut `PENDING`.
84
+
85
+ ```python
86
+ # Lister (pagination + filtre optionnels)
87
+ page = efact.invoices.list(page=0, size=20, status="ACCEPTED")
88
+ for inv in page.content:
89
+ print(inv.invoice_number, inv.status)
90
+
91
+ # Suivre la clairance DGI
92
+ status = efact.invoices.retrieve_status(invoice.id)
93
+ print(status.status, status.dgi_reference)
94
+ ```
95
+
96
+ ## Gestion des erreurs
97
+
98
+ Toutes les erreurs héritent de `EFactError`. Les réponses non-OK de l'API
99
+ sont converties en erreurs typées portant `code`, `http_status` et `errors`.
100
+
101
+ ```python
102
+ from efact import (
103
+ EFactApiError,
104
+ EFactAuthError,
105
+ EFactValidationError,
106
+ EFactNotFoundError,
107
+ EFactConflictError,
108
+ EFactConnectionError,
109
+ EFactTimeoutError,
110
+ )
111
+
112
+ try:
113
+ efact.invoices.create(data)
114
+ except EFactValidationError as e:
115
+ print("Champs invalides :", e.errors)
116
+ except EFactAuthError:
117
+ print("Clé API manquante ou invalide.")
118
+ except EFactConflictError:
119
+ print("Facture non modifiable (statut ≠ PENDING).")
120
+ except EFactApiError as e:
121
+ print(e.code, e.http_status, e)
122
+ except EFactTimeoutError:
123
+ print("Délai dépassé.")
124
+ except EFactConnectionError:
125
+ print("Échec réseau.")
126
+ ```
127
+
128
+ | Erreur | Cas |
129
+ | --- | --- |
130
+ | `EFactConfigError` | Mauvaise configuration (avant tout appel réseau) |
131
+ | `EFactAuthError` | 401/403 — clé manquante/invalide |
132
+ | `EFactValidationError` | 400/422 — champs invalides (`errors`) |
133
+ | `EFactNotFoundError` | 404 — introuvable (inclut cross-tenant) |
134
+ | `EFactConflictError` | 409 — facture non modifiable/annulable |
135
+ | `EFactApiError` | autre erreur API |
136
+ | `EFactTimeoutError` | délai dépassé |
137
+ | `EFactConnectionError` | échec réseau |
138
+
139
+ Les méthodes sûres (`GET`/`PUT`/`DELETE`) sont automatiquement rejouées sur
140
+ les erreurs transitoires (408, 425, 429, 5xx, coupures réseau) avec back-off
141
+ exponentiel et respect de `Retry-After`. `POST` (création) n'est jamais rejoué.
142
+
143
+ ## Sécurité
144
+
145
+ - La clé n'est attachée qu'en `Authorization: Bearer <clé>`, jamais dans l'URL.
146
+ - `efact.get_config()` ne renvoie qu'une version masquée de la clé.
147
+ - Les messages d'erreur n'incluent jamais la clé ni le corps brut de la réponse.
148
+
149
+ ## Licence
150
+
151
+ [MIT](./LICENSE)
@@ -0,0 +1,61 @@
1
+ """SDK Python officiel EFact — e-facturation (DGI Maroc).
2
+
3
+ Surface publique du SDK. Les types du contrat sont réexportés depuis
4
+ `efact._generated` (régénérés depuis l'OpenAPI) : un changement de champ côté
5
+ API se propage ici automatiquement.
6
+ """
7
+
8
+ from efact.client import ENVIRONMENTS, EFact
9
+ from efact.errors import (
10
+ AUTH_ERROR_CODES,
11
+ CONFLICT_ERROR_CODES,
12
+ VALIDATION_ERROR_CODES,
13
+ EFactApiError,
14
+ EFactAuthError,
15
+ EFactConfigError,
16
+ EFactConflictError,
17
+ EFactConnectionError,
18
+ EFactError,
19
+ EFactNotFoundError,
20
+ EFactTimeoutError,
21
+ EFactValidationError,
22
+ create_api_error,
23
+ )
24
+ from efact.invoices import InvoicesResource
25
+
26
+ # Types du contrat (générés).
27
+ from efact._generated.models.create_invoice_line_request import CreateInvoiceLineRequest
28
+ from efact._generated.models.create_invoice_request import CreateInvoiceRequest
29
+ from efact._generated.models.field_error import FieldError
30
+ from efact._generated.models.invoice_response import InvoiceResponse
31
+ from efact._generated.models.invoice_status_response import InvoiceStatusResponse
32
+ from efact._generated.models.page_response_invoice_response import PageResponseInvoiceResponse
33
+ from efact._generated.models.update_invoice_request import UpdateInvoiceRequest
34
+
35
+ __all__ = [
36
+ "EFact",
37
+ "ENVIRONMENTS",
38
+ "InvoicesResource",
39
+ # Erreurs
40
+ "EFactError",
41
+ "EFactConfigError",
42
+ "EFactConnectionError",
43
+ "EFactTimeoutError",
44
+ "EFactApiError",
45
+ "EFactAuthError",
46
+ "EFactValidationError",
47
+ "EFactNotFoundError",
48
+ "EFactConflictError",
49
+ "create_api_error",
50
+ "AUTH_ERROR_CODES",
51
+ "CONFLICT_ERROR_CODES",
52
+ "VALIDATION_ERROR_CODES",
53
+ # Types générés
54
+ "CreateInvoiceRequest",
55
+ "CreateInvoiceLineRequest",
56
+ "UpdateInvoiceRequest",
57
+ "InvoiceResponse",
58
+ "InvoiceStatusResponse",
59
+ "PageResponseInvoiceResponse",
60
+ "FieldError",
61
+ ]
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+
3
+ # flake8: noqa
4
+
5
+ """
6
+ EFact API
7
+
8
+ Compliance-as-a-service backend for Moroccan DGI electronic invoicing
9
+
10
+ The version of the OpenAPI document: v0.0.1-SNAPSHOT
11
+ Contact: contact@itzenata.com
12
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
13
+
14
+ Do not edit the class manually.
15
+ """ # noqa: E501
16
+
17
+
18
+ __version__ = "1.0.0"
19
+
20
+ # import apis into sdk package
21
+ from efact._generated.api.invoices_api import InvoicesApi
22
+
23
+ # import ApiClient
24
+ from efact._generated.api_response import ApiResponse
25
+ from efact._generated.api_client import ApiClient
26
+ from efact._generated.configuration import Configuration
27
+ from efact._generated.exceptions import OpenApiException
28
+ from efact._generated.exceptions import ApiTypeError
29
+ from efact._generated.exceptions import ApiValueError
30
+ from efact._generated.exceptions import ApiKeyError
31
+ from efact._generated.exceptions import ApiAttributeError
32
+ from efact._generated.exceptions import ApiException
33
+
34
+ # import models into sdk package
35
+ from efact._generated.models.api_response_invoice_response import ApiResponseInvoiceResponse
36
+ from efact._generated.models.api_response_invoice_status_response import ApiResponseInvoiceStatusResponse
37
+ from efact._generated.models.api_response_page_response_invoice_response import ApiResponsePageResponseInvoiceResponse
38
+ from efact._generated.models.create_invoice_line_request import CreateInvoiceLineRequest
39
+ from efact._generated.models.create_invoice_request import CreateInvoiceRequest
40
+ from efact._generated.models.field_error import FieldError
41
+ from efact._generated.models.invoice_response import InvoiceResponse
42
+ from efact._generated.models.invoice_status_response import InvoiceStatusResponse
43
+ from efact._generated.models.page_response_invoice_response import PageResponseInvoiceResponse
44
+ from efact._generated.models.update_invoice_request import UpdateInvoiceRequest
@@ -0,0 +1,5 @@
1
+ # flake8: noqa
2
+
3
+ # import apis into api package
4
+ from efact._generated.api.invoices_api import InvoicesApi
5
+