pyrentri 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.
@@ -0,0 +1,236 @@
1
+
2
+ # Created by https://www.toptal.com/developers/gitignore/api/python,pycharm+all
3
+ # Edit at https://www.toptal.com/developers/gitignore?templates=python,pycharm+all
4
+
5
+ ### PyCharm+all ###
6
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
7
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
8
+
9
+ # User-specific stuff
10
+ .idea/**/workspace.xml
11
+ .idea/**/tasks.xml
12
+ .idea/**/usage.statistics.xml
13
+ .idea/**/dictionaries
14
+ .idea/**/shelf
15
+
16
+ # Generated files
17
+ .idea/**/contentModel.xml
18
+
19
+ # Sensitive or high-churn files
20
+ .idea/**/dataSources/
21
+ .idea/**/dataSources.ids
22
+ .idea/**/dataSources.local.xml
23
+ .idea/**/sqlDataSources.xml
24
+ .idea/**/dynamic.xml
25
+ .idea/**/uiDesigner.xml
26
+ .idea/**/dbnavigator.xml
27
+
28
+ # Gradle
29
+ .idea/**/gradle.xml
30
+ .idea/**/libraries
31
+
32
+ # Gradle and Maven with auto-import
33
+ # When using Gradle or Maven with auto-import, you should exclude module files,
34
+ # since they will be recreated, and may cause churn. Uncomment if using
35
+ # auto-import.
36
+ # .idea/artifacts
37
+ # .idea/compiler.xml
38
+ # .idea/jarRepositories.xml
39
+ # .idea/modules.xml
40
+ # .idea/*.iml
41
+ # .idea/modules
42
+ # *.iml
43
+ # *.ipr
44
+
45
+ # CMake
46
+ cmake-build-*/
47
+
48
+ # Mongo Explorer plugin
49
+ .idea/**/mongoSettings.xml
50
+
51
+ # File-based project format
52
+ *.iws
53
+
54
+ # IntelliJ
55
+ out/
56
+
57
+ # mpeltonen/sbt-idea plugin
58
+ .idea_modules/
59
+
60
+ # JIRA plugin
61
+ atlassian-ide-plugin.xml
62
+
63
+ # Cursive Clojure plugin
64
+ .idea/replstate.xml
65
+
66
+ # Crashlytics plugin (for Android Studio and IntelliJ)
67
+ com_crashlytics_export_strings.xml
68
+ crashlytics.properties
69
+ crashlytics-build.properties
70
+ fabric.properties
71
+
72
+ # Editor-based Rest Client
73
+ .idea/httpRequests
74
+
75
+ # Android studio 3.1+ serialized cache file
76
+ .idea/caches/build_file_checksums.ser
77
+
78
+ ### PyCharm+all Patch ###
79
+ # Ignores the whole .idea folder and all .iml files
80
+ # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
81
+
82
+ .idea/
83
+
84
+ # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
85
+
86
+ *.iml
87
+ modules.xml
88
+ .idea/misc.xml
89
+ *.ipr
90
+
91
+ # Sonarlint plugin
92
+ .idea/sonarlint
93
+
94
+ ### Python ###
95
+ # Byte-compiled / optimized / DLL files
96
+ __pycache__/
97
+ *.py[cod]
98
+ *$py.class
99
+
100
+ # C extensions
101
+ *.so
102
+
103
+ # Distribution / packaging
104
+ .Python
105
+ build/
106
+ develop-eggs/
107
+ dist/
108
+ downloads/
109
+ eggs/
110
+ .eggs/
111
+ lib/
112
+ lib64/
113
+ parts/
114
+ sdist/
115
+ var/
116
+ wheels/
117
+ pip-wheel-metadata/
118
+ share/python-wheels/
119
+ *.egg-info/
120
+ .installed.cfg
121
+ *.egg
122
+ MANIFEST
123
+
124
+ # PyInstaller
125
+ # Usually these files are written by a python script from a template
126
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
127
+ *.manifest
128
+ *.spec
129
+
130
+ # Installer logs
131
+ pip-log.txt
132
+ pip-delete-this-directory.txt
133
+
134
+ # Unit test / coverage reports
135
+ htmlcov/
136
+ .tox/
137
+ .nox/
138
+ .coverage
139
+ .coverage.*
140
+ .cache
141
+ nosetests.xml
142
+ coverage.xml
143
+ *.cover
144
+ *.py,cover
145
+ .hypothesis/
146
+ .pytest_cache/
147
+ pytestdebug.log
148
+
149
+ # Translations
150
+ *.mo
151
+ *.pot
152
+
153
+ # Django stuff:
154
+ *.log
155
+ local_settings.py
156
+ db.sqlite3
157
+ db.sqlite3-journal
158
+
159
+ # Flask stuff:
160
+ instance/
161
+ .webassets-cache
162
+
163
+ # Scrapy stuff:
164
+ .scrapy
165
+
166
+ # Sphinx documentation
167
+ docs/_build/
168
+ doc/_build/
169
+
170
+ # PyBuilder
171
+ target/
172
+
173
+ # Jupyter Notebook
174
+ .ipynb_checkpoints
175
+
176
+ # IPython
177
+ profile_default/
178
+ ipython_config.py
179
+
180
+ # pyenv
181
+ .python-version
182
+
183
+ # pipenv
184
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
185
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
186
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
187
+ # install all needed dependencies.
188
+ #Pipfile.lock
189
+
190
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
191
+ __pypackages__/
192
+
193
+ # Celery stuff
194
+ celerybeat-schedule
195
+ celerybeat.pid
196
+
197
+ # SageMath parsed files
198
+ *.sage.py
199
+
200
+ # Environments
201
+ .env
202
+ .venv
203
+ env/
204
+ venv/
205
+ ENV/
206
+ env.bak/
207
+ venv.bak/
208
+
209
+ # Spyder project settings
210
+ .spyderproject
211
+ .spyproject
212
+
213
+ # Rope project settings
214
+ .ropeproject
215
+
216
+ # mkdocs documentation
217
+ /site
218
+
219
+ # mypy
220
+ .mypy_cache/
221
+ .dmypy.json
222
+ dmypy.json
223
+
224
+ # Pyre type checker
225
+ .pyre/
226
+
227
+ # pytype static type analyzer
228
+ .pytype/
229
+
230
+ # End of https://www.toptal.com/developers/gitignore/api/python,pycharm+all
231
+
232
+ config.ini
233
+ main2.py
234
+ *.p12
235
+ *.cer
236
+ .pypirc
pyrentri-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Antonio Porcelli (Progressify)
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,230 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyrentri
3
+ Version: 0.1.0
4
+ Summary: Simple API Wrapper for RENTRI (Registro Elettronico Nazionale per la Tracciabilità dei Rifiuti)
5
+ Home-page: https://github.com/progressify/pyrentri
6
+ Author: Progressify
7
+ Author-email: antonio@progressify.dev
8
+ License: MIT
9
+ Keywords: rentri,api,sdk
10
+ Classifier: Programming Language :: Python
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.7
13
+ Requires-Python: >=3.7
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: configparser
17
+ Requires-Dist: requests
18
+ Requires-Dist: cryptography
19
+ Requires-Dist: PyJWT
20
+ Dynamic: license-file
21
+
22
+ <img src="https://progressify.dev/img/progressify-logo.png" alt="logo" height="120" align="right" />
23
+
24
+ # pyrentri
25
+
26
+ **A lightweight Python wrapper for the Italian RENTRI API (Registro Elettronico Nazionale per la Tracciabilità dei Rifiuti).**
27
+
28
+ [![PyPI version](https://img.shields.io/pypi/v/pyrentri.svg)](https://pypi.org/project/pyrentri/)
29
+ [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/progressify/pyrentri/graphs/commit-activity)
30
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
31
+ [![Paypal Donate](https://img.shields.io/badge/PayPal-Donate%20to%20Author-blue.svg)](https://www.paypal.me/progressify)
32
+ [![Satispay Donate](https://img.shields.io/badge/Satispay-Donate%20to%20Author-red.svg)](https://tag.satispay.com/progressify)
33
+ [![Ask Me Anything !](https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg)](https://github.com/progressify/pyrentri/issues)
34
+
35
+ ---
36
+
37
+ 🌐 **Languages / Lingue**: **🇬🇧 English** | [🇮🇹 Leggi in Italiano](https://github.com/progressify/pyrentri/blob/master/README.it.md)
38
+
39
+ ---
40
+
41
+ ## ⚠️ Important Disclaimer & Library Scope
42
+
43
+ > **`pyrentri` is an authentication and transport bridge, NOT a replacement for the official RENTRI platform or its data specifications.**
44
+ >
45
+ > - **What this library DOES**: It automates the complex security and cryptographic workflow required by RENTRI. It handles `.p12` (PKCS#12) certificate parsing (RSA and Elliptic Curve), generates signed JWT tokens with certificate chains (`x5c`), computes SHA-256 payload digests for `signed_headers`, and simplifies HTTP communication.
46
+ > - **What this library DOES NOT do**: It does **not** validate, construct, or alter business payloads (e.g., FIR forms, waste registry movements). As a developer, you must consult the [official RENTRI documentation](https://demoapi.rentri.gov.it/docs?page=home#lista-dei-servizi-di-interoperabilit-resi-disponibili-tramite-api) and build the request JSON payloads and process responses according to official regulatory standards.
47
+
48
+ ---
49
+
50
+ ## 💡 Background & Origin
51
+
52
+ This project originated from the practical need to explore, test, and validate the technical specifications and interoperability flows of the RENTRI APIs while supporting a client in designing their internal corporate SDK.
53
+
54
+ This wrapper was developed independently as a personal sandbox and testing tool to verify API behaviors and the proper interpretation of the official documentation. The open-sourced code is 100% original, served solely for personal aid until its public release, and does not violate any non-disclosure agreements or existing contractual obligations. It is shared with the community to help other developers bypass the initial complexity of RENTRI's cryptographic and authentication layer.
55
+
56
+ ---
57
+
58
+ ## Features
59
+
60
+ - 🔐 **Automated PKCS#12 Handling**: Reads private keys and X.509 certificates from `.p12` files.
61
+ - ⚡ **Auto-detect Signature Algorithm**: Supports both RSA (`RS256`) and Elliptic Curve (`ES256`) keys.
62
+ - 🛡️ **JWT & Digest Generation**: Formats tokens with the certificate chain (`x5c`) and automatically hashes payload bodies (`SHA-256` digest).
63
+ - 🔄 **Multi-Environment**: Seamlessly switch between Demo/Sandbox (`demoapi.rentri.gov.it`) and Production (`api.rentri.gov.it`).
64
+ - 🔒 **Secure Configuration**: Supports `config.ini` and environment variables (`P12_PASSWORD`) for Docker and cloud deployments.
65
+
66
+ ---
67
+
68
+ ## Installation
69
+
70
+ Install using `pip`:
71
+
72
+ ```bash
73
+ pip install pyrentri
74
+ ```
75
+
76
+ Or add it to your `requirements.txt`:
77
+
78
+ ```txt
79
+ pyrentri>=0.1.0
80
+ ```
81
+
82
+ You can also install the latest development version directly from GitHub:
83
+
84
+ ```bash
85
+ pip install git+https://github.com/progressify/pyrentri.git
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Configuration
91
+
92
+ `pyrentri` reads its configuration from a `config.ini` file located in your project directory (or a custom path passed to the constructor).
93
+
94
+ ### 1. `config.ini`
95
+
96
+ Create a `config.ini` file based on the provided template:
97
+
98
+ ```ini
99
+ [RENTRI]
100
+ sandbox = True
101
+ p12_path = ./your_certificate.p12
102
+ p12_password = your_p12_password
103
+ vat_number = 12345678901
104
+ ```
105
+
106
+ - **`sandbox`**: Set to `True` for the demo/testing environment (`demoapi.rentri.gov.it`) or `False` for production (`api.rentri.gov.it`).
107
+ - **`p12_path`**: Path to your PKCS#12 certificate file (`.p12`).
108
+ - **`p12_password`**: Password for your `.p12` file.
109
+ - **`vat_number`**: Fiscal code / VAT number associated with the RENTRI accreditation.
110
+
111
+ ### 2. Environment Variables (Recommended for Production & Docker)
112
+
113
+ To avoid storing passwords in plain text inside `config.ini`, you can set the `P12_PASSWORD` environment variable. If set, it will override the password defined in the INI file:
114
+
115
+ ```bash
116
+ export P12_PASSWORD="your_secure_password"
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Usage
122
+
123
+ ### 1. Initialize the Wrapper
124
+
125
+ ```python
126
+ from pyrentri import RentriWrapper
127
+
128
+ # Reads config.ini from the current directory
129
+ rentri = RentriWrapper()
130
+ ```
131
+
132
+ ### 2. Check Service Status
133
+
134
+ Verify connection and operational status of a specific RENTRI API service (e.g. `formulari`, `anagrafiche`, `dati-registri`):
135
+
136
+ ```python
137
+ from pyrentri.rentri_enum import RENTRIStatus
138
+
139
+ status, response = rentri.status_api("formulari")
140
+
141
+ if status == RENTRIStatus.OK:
142
+ print("Service is operational:", response)
143
+ elif status == RENTRIStatus.WARNING:
144
+ print("Service warning:", response)
145
+ else:
146
+ print("Service error or unavailable:", response)
147
+ ```
148
+
149
+ ### 3. Send Authenticated Requests (with JWT & Payload Digest)
150
+
151
+ When sending requests with a JSON body, RENTRI requires a signed JWT containing a SHA-256 digest of the payload. Use `create_jwt_token` to generate the token and digest, then send the request:
152
+
153
+ ```python
154
+ # 1. Define your business payload according to the official RENTRI specifications
155
+ payload = {
156
+ "num_iscr_sito": "OP2501KCJ031133-NA0001",
157
+ "dati_partenza": {
158
+ # Your form/movement fields here...
159
+ }
160
+ }
161
+
162
+ # 2. Generate signed JWT token and SHA-256 digest
163
+ token, digest = rentri.create_jwt_token(content=payload, content_type="application/json")
164
+
165
+ # 3. Prepare headers
166
+ headers = {
167
+ "Authorization": f"Bearer {token}",
168
+ "Agid-JWT-Signature": token,
169
+ "Digest": digest,
170
+ "Content-Type": "application/json",
171
+ "Accept": "application/json, application/problem+json"
172
+ }
173
+
174
+ # 4. Perform the POST request
175
+ response = rentri.post("/formulari/v1.0/creazione", data=payload, headers=headers)
176
+ print("Response:", response)
177
+ ```
178
+
179
+ Similarly, for `GET` requests:
180
+
181
+ ```python
182
+ # GET request without payload
183
+ token, _ = rentri.create_jwt_token()
184
+
185
+ headers = {
186
+ "Authorization": f"Bearer {token}",
187
+ "Accept": "application/json, application/problem+json"
188
+ }
189
+
190
+ response = rentri.get("/codifiche/v1.0/lookup/nazioni?lang=it", headers=headers)
191
+ print("Nazioni:", response)
192
+ ```
193
+
194
+ ---
195
+
196
+ ## Documentation & Official Resources
197
+
198
+ - **Official RENTRI API Docs**: [demoapi.rentri.gov.it/docs](https://demoapi.rentri.gov.it/docs?page=home#lista-dei-servizi-di-interoperabilit-resi-disponibili-tramite-api)
199
+ - **Official RENTRI Portal**: [www.rentri.gov.it](https://www.rentri.gov.it)
200
+
201
+ ---
202
+
203
+ ## 💼 Commercial Support & Consulting
204
+
205
+ Need to integrate the RENTRI APIs into your corporate ERP, custom software, or cloud infrastructure?
206
+
207
+ I offer specialized technical consulting and tailored development services:
208
+ - Robust architectures for asynchronous batch transmissions and status polling.
209
+ - Secure certificate management and digital signature pipelines in cloud and on-premise environments.
210
+
211
+ 📩 **Get in touch**: send an email to antonio@progressify.dev or visit **[progressify.dev](https://progressify.dev)** to discuss your integration needs.
212
+
213
+ ---
214
+
215
+ ## Author & Support
216
+
217
+ Developed with ❤️ by **[Antonio Porcelli (Progressify)](https://progressify.dev)**.
218
+
219
+ If this project helps you or saves you time, please consider supporting its maintenance:
220
+
221
+ - ☕ [Donate via PayPal](https://www.paypal.me/progressify)
222
+ - 💳 [Donate via Satispay](https://tag.satispay.com/progressify)
223
+ - 💬 [Open an Issue / Ask a Question](https://github.com/progressify/pyrentri/issues)
224
+
225
+ ---
226
+
227
+ ## License
228
+
229
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
230
+
@@ -0,0 +1,211 @@
1
+ <img src="https://progressify.dev/img/progressify-logo.png" alt="logo" height="120" align="right" />
2
+
3
+ # pyrentri
4
+
5
+ **Un wrapper Python per l'interoperabilità con le API di RENTRI (Registro Elettronico Nazionale per la Tracciabilità dei Rifiuti).**
6
+
7
+ [![PyPI version](https://img.shields.io/pypi/v/pyrentri.svg)](https://pypi.org/project/pyrentri/)
8
+ [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/progressify/pyrentri/graphs/commit-activity)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
+ [![Paypal Donate](https://img.shields.io/badge/PayPal-Donate%20to%20Author-blue.svg)](https://www.paypal.me/progressify)
11
+ [![Satispay Donate](https://img.shields.io/badge/Satispay-Donate%20to%20Author-red.svg)](https://tag.satispay.com/progressify)
12
+ [![Ask Me Anything !](https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg)](https://github.com/progressify/pyrentri/issues)
13
+
14
+ ---
15
+
16
+ 🌐 **Lingue / Languages**: [🇬🇧 Read in English](https://github.com/progressify/pyrentri/blob/master/README.md) | **🇮🇹 Italiano**
17
+
18
+ ---
19
+
20
+ ## ⚠️ Disclaimer Importante & Scopo della Libreria
21
+
22
+ > **`pyrentri` è uno strumento per la gestione dell'autenticazione e del trasporto HTTP, NON un sostituto della piattaforma ufficiale RENTRI né delle sue specifiche sui dati.**
23
+ >
24
+ > - **Cosa FA questa libreria**: Automatizza interamente il complesso flusso di sicurezza e crittografia richiesto dalle specifiche RENTRI. Gestisce l'estrazione e il parsing dei certificati `.p12` (PKCS#12) con supporto per chiavi RSA ed Elliptic Curve, la generazione dei token JWT firmati con la catena di certificati (`x5c`), il calcolo del digest SHA-256 dei payload per gli `signed_headers`, e semplifica le chiamate HTTP verso gli endpoint governativi.
25
+ > - **Cosa NON FA questa libreria**: Non valida, non costruisce e non altera i payload (es. formulari FIR, movimentazioni del registro cronologico). In qualità di sviluppatore, è tuo compito consultare la [documentazione ufficiale di RENTRI](https://demoapi.rentri.gov.it/docs?page=home#lista-dei-servizi-di-interoperabilit-resi-disponibili-tramite-api) e strutturare i payload JSON delle richieste e processare le relative risposte in piena conformità con gli standard normativi.
26
+
27
+ ---
28
+
29
+ ## 💡 Contesto & Origine del Progetto
30
+
31
+ Questo progetto nasce dall'esigenza pratica di approfondire e testare sul campo le specifiche tecniche e i flussi di interoperabilità delle API di RENTRI, a supporto delle attività di studio e progettazione di un SDK interno per un cliente.
32
+
33
+ Il presente wrapper è stato realizzato in totale autonomia come strumento personale di ausilio, prototipazione e collaudo per verificare il funzionamento dei servizi e la corretta interpretazione della documentazione ufficiale. Il codice pubblicato è originale al 100%, è stato ad esclusivo uso personale fino al momento della pubblicazione e non viola alcun accordo di riservatezza o vincolo contrattuale in essere. Viene condiviso con la community open source per semplificare a sviluppatori e aziende la gestione del livello crittografico e di autenticazione governativa.
34
+
35
+ ---
36
+
37
+ ## Caratteristiche
38
+
39
+ - 🔐 **Gestione Automatica PKCS#12**: Estrazione sicura di chiave privata e certificato X.509 da file `.p12`.
40
+ - ⚡ **Riconoscimento Automatico dell'Algoritmo di Firma**: Supporto per chiavi RSA (`RS256`) ed Elliptic Curve (`ES256`).
41
+ - 🛡️ **Generazione Token JWT & Digest**: Composizione automatica dell'header `x5c` con il certificato in Base64 e hashing del body con `SHA-256` per l'integrità dei dati.
42
+ - 🔄 **Supporto Multi-Ambiente**: Passaggio immediato tra ambiente Demo/Sandbox (`demoapi.rentri.gov.it`) e Produzione (`api.rentri.gov.it`).
43
+ - 🔒 **Configurazione Flessibile e Sicura**: Supporto a file `config.ini` e variabile d'ambiente (`P12_PASSWORD`) per l'impiego in container Docker e ambienti cloud.
44
+
45
+ ---
46
+
47
+ ## Installazione
48
+
49
+ Installazione tramite `pip`:
50
+
51
+ ```bash
52
+ pip install pyrentri
53
+ ```
54
+
55
+ Oppure aggiungendolo al file `requirements.txt`:
56
+
57
+ ```txt
58
+ pyrentri>=0.1.0
59
+ ```
60
+
61
+ È inoltre possibile installare l'ultima versione di sviluppo direttamente da GitHub:
62
+
63
+ ```bash
64
+ pip install git+https://github.com/progressify/pyrentri.git
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Configurazione
70
+
71
+ `pyrentri` legge le credenziali di accesso da un file `config.ini` presente nella cartella di lavoro (o a un percorso personalizzato passato come parametro).
72
+
73
+ ### 1. `config.ini`
74
+
75
+ Crea un file `config.ini` basandoti sul modello fornito:
76
+
77
+ ```ini
78
+ [RENTRI]
79
+ sandbox = True
80
+ p12_path = ./tuo_certificato.p12
81
+ p12_password = tua_password_p12
82
+ vat_number = 12345678901
83
+ ```
84
+
85
+ - **`sandbox`**: Imposta su `True` per l'ambiente di test/demo (`demoapi.rentri.gov.it`) oppure `False` per l'ambiente di produzione (`api.rentri.gov.it`).
86
+ - **`p12_path`**: Percorso al file del certificato PKCS#12 (`.p12`).
87
+ - **`p12_password`**: Password di protezione del certificato `.p12`.
88
+ - **`vat_number`**: Partita IVA o Codice Fiscale dell'ente/azienda accreditata su RENTRI.
89
+
90
+ ### 2. Variabili d'Ambiente (Consigliato in Produzione e con Docker)
91
+
92
+ Per evitare di inserire la password in chiaro nel file `config.ini`, puoi impostare la variabile d'ambiente `P12_PASSWORD`. Se presente, avrà la precedenza rispetto alla password indicata nel file INI:
93
+
94
+ ```bash
95
+ export P12_PASSWORD="tua_password_sicura"
96
+ ```
97
+
98
+ ---
99
+
100
+ ## Utilizzo
101
+
102
+ ### 1. Inizializzazione del Client
103
+
104
+ ```python
105
+ from pyrentri import RentriWrapper
106
+
107
+ # Inizializza leggendo config.ini dalla directory corrente
108
+ rentri = RentriWrapper()
109
+
110
+ # È possibile specificare un percorso alternativo:
111
+ # rentri = RentriWrapper(config_path="/path/to/config/")
112
+ ```
113
+
114
+ ### 2. Verifica Stato dei Servizi
115
+
116
+ Verifica lo stato operativo e la connettività di un servizio RENTRI specifico (es. `formulari`, `anagrafiche`, `dati-registri`):
117
+
118
+ ```python
119
+ from pyrentri.rentri_enum import RENTRIStatus
120
+
121
+ status, response = rentri.status_api("formulari")
122
+
123
+ if status == RENTRIStatus.OK:
124
+ print("Servizio operativo:", response)
125
+ elif status == RENTRIStatus.WARNING:
126
+ print("Avviso sul servizio:", response)
127
+ else:
128
+ print("Errore o servizio non disponibile:", response)
129
+ ```
130
+
131
+ ### 3. Invio Richieste Autenticate (con JWT e Digest del Payload)
132
+
133
+ Per le richieste che inviano un payload JSON (es. `POST` o `PUT`), le specifiche RENTRI richiedono un JWT firmato contenente il digest SHA-256 del corpo. Usa `create_jwt_token` per generare token e digest, quindi effettua la chiamata:
134
+
135
+ ```python
136
+ # 1. Definisci il payload secondo le specifiche ufficiali RENTRI
137
+ payload = {
138
+ "num_iscr_sito": "OP2501KCJ031133-NA0001",
139
+ "dati_partenza": {
140
+ # Campi del formulario / movimentazione...
141
+ }
142
+ }
143
+
144
+ # 2. Genera il token JWT firmato e il relativo digest SHA-256
145
+ token, digest = rentri.create_jwt_token(content=payload, content_type="application/json")
146
+
147
+ # 3. Prepara gli header HTTP richiesti
148
+ headers = {
149
+ "Authorization": f"Bearer {token}",
150
+ "Agid-JWT-Signature": token,
151
+ "Digest": digest,
152
+ "Content-Type": "application/json",
153
+ "Accept": "application/json, application/problem+json"
154
+ }
155
+
156
+ # 4. Esegui la richiesta POST
157
+ response = rentri.post("/formulari/v1.0/creazione", data=payload, headers=headers)
158
+ print("Risposta:", response)
159
+ ```
160
+
161
+ Allo stesso modo, per richieste `GET` (senza payload):
162
+
163
+ ```python
164
+ # Richiesta GET senza payload
165
+ token, _ = rentri.create_jwt_token()
166
+
167
+ headers = {
168
+ "Authorization": f"Bearer {token}",
169
+ "Accept": "application/json, application/problem+json"
170
+ }
171
+
172
+ response = rentri.get("/codifiche/v1.0/lookup/nazioni?lang=it", headers=headers)
173
+ print("Nazioni:", response)
174
+ ```
175
+
176
+ ---
177
+
178
+ ## Documentazione & Risorse Ufficiali
179
+
180
+ - **Documentazione Ufficiale API RENTRI**: [demoapi.rentri.gov.it/docs](https://demoapi.rentri.gov.it/docs?page=home#lista-dei-servizi-di-interoperabilit-resi-disponibili-tramite-api)
181
+ - **Portale Ufficiale RENTRI**: [www.rentri.gov.it](https://www.rentri.gov.it)
182
+
183
+ ---
184
+
185
+ ## 💼 Consulenza & Sviluppo Personalizzato
186
+
187
+ Hai bisogno di integrare le API di RENTRI all'interno del tuo software gestionale, ERP o nella tua infrastruttura aziendale?
188
+
189
+ Offro supporto tecnico specializzato e servizi di sviluppo su misura:
190
+ - Architetture per la gestione asincrona delle trasmissioni massive e monitoraggio degli esiti.
191
+ - Gestione della firma digitale e dei certificati in ambienti di produzione e cloud.
192
+
193
+ 📩 **Contattami**: invia un'email a antonio@progressify.dev o visita il sito **[progressify.dev](https://progressify.dev)** per valutare insieme le tue esigenze di integrazione.
194
+
195
+ ---
196
+
197
+ ## Autore & Supporto
198
+
199
+ Sviluppato con ❤️ da **[Antonio Porcelli (Progressify)](https://progressify.dev)**.
200
+
201
+ Se questo progetto ti è stato utile o ti ha fatto risparmiare tempo, valuta una donazione per supportarne la manutenzione:
202
+
203
+ - ☕ [Dona con PayPal](https://www.paypal.me/progressify)
204
+ - 💳 [Dona con Satispay](https://tag.satispay.com/progressify)
205
+ - 💬 [Apri una Segnalazione / Fai una Domanda](https://github.com/progressify/pyrentri/issues)
206
+
207
+ ---
208
+
209
+ ## Licenza
210
+
211
+ Questo progetto è rilasciato sotto licenza MIT - consulta il file [LICENSE](LICENSE) per i dettagli.