Comuni Italiani
Libreria Python per cercare informazioni sui comuni italiani usando i dati ISTAT, con arricchimento automatico dei CAP tramite il dataset di Garda Informatica.
Caratteristiche
- Ricerca di un comune per nome, case-insensitive e robusta agli accenti
- Ricerca per codice catastale
- Elenco dei comuni per provincia
- Ricerca inversa per
CAP - Download automatico e aggiornamento del dataset ISTAT
- Download automatico dell'ultimo dataset CAP disponibile da Garda Informatica
Installazione
pip install comuniitaliani
Utilizzo
from comuniitaliani import Comuni
comuni = Comuni()
Cercare un comune per nome
info = comuni.cerca_comune("Agliè")
print(info)
Output di esempio:
{
"nome": "Agliè",
"provincia": "Torino",
"sigla_provincia": "TO",
"regione": "Piemonte",
"codice_catastale": "A074",
"cap": ["10080"]
}
Cercare un comune per codice catastale
info = comuni.cerca_per_codice_catastale("A074")
print(info)
Elencare i comuni di una provincia
torino = comuni.comuni_per_provincia("TO")
print(torino[:3])
Cercare i comuni associati a un CAP
risultati = comuni.cerca_per_cap("10080")
print(risultati)
Output di esempio:
[
{
"nome": "Agliè",
"provincia": "Torino",
"sigla_provincia": "TO",
"regione": "Piemonte",
"codice_catastale": "A074",
"cap": ["10080"]
}
]
Note sui CAP
Il campo cap viene restituito sempre come lista:
- un comune può avere più CAP
- uno stesso CAP può essere associato a più comuni
Per questo cerca_per_cap() restituisce una lista di comuni.
L'associazione dei CAP privilegia chiavi affidabili nell'ordine:
- codice ISTAT alfanumerico
- codice ISTAT numerico
- codice catastale
- nome comune + sigla provincia
Non viene usato il solo nome comune, per evitare match ambigui.
Aggiornamento automatico dei dati
Per default la libreria:
- verifica se il CSV ISTAT locale è aggiornato
- include nel pacchetto uno snapshot locale del dataset CAP, utile anche offline
- risolve l'ultimo ZIP disponibile dalla pagina di Garda Informatica
- scarica il dataset CAP solo se la versione remota è cambiata
Se vuoi lavorare solo con file già presenti in locale:
comuni = Comuni(allow_download=False)
Se vuoi disabilitare completamente il layer CAP:
comuni = Comuni(load_cap=False)
Se vuoi indicare esplicitamente un file CAP locale:
comuni = Comuni(cap_csv_file="/percorso/garda_cap.csv", allow_download=False)
Fonti dati
- ISTAT per anagrafica comuni
- Garda Informatica per l'associazione CAP
Compatibilita API
Dalla versione 0.22.1 le funzioni che restituiscono dati di comune includono anche il campo cap.
Il campo e sempre una lista, anche quando esiste un solo CAP.
Sviluppo
Installazione dipendenze di sviluppo:
pip install -e . -r requirements-dev.txt
Esecuzione test:
pytest
Licenza
Il progetto è distribuito con licenza MIT. Vedi LICENSE.
Link utili
Metadata
Release files for comuniitaliani 0.22.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| comuniitaliani-0.22.1.tar.gz | 220.2 kB | Without provenance | Details for comuniitaliani-0.22.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| comuniitaliani-0.22.1-py3-none-any.whl | Python 3 | none | any | Details for comuniitaliani-0.22.1-py3-none-any.whl |
Total release size: 438.8 kB
Release files / comuniitaliani-0.22.1.tar.gz
| Download URL | comuniitaliani-0.22.1.tar.gz |
|---|---|
| Size | 220.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d049f4c55e07dfaf9c3a1914d4a9d9eaf6b028ef2e2cdf1670b95cf0fbc82b87
|
|
BLAKE2b-256 checksum How to use checksums |
4f133efaf5b85821e1f2e3860103e5a0af1d93cd3dbf4d7866a6731855e9474b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / comuniitaliani-0.22.1-py3-none-any.whl
| Download URL | comuniitaliani-0.22.1-py3-none-any.whl |
|---|---|
| Size | 218.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4dd92629ece2cd5a17c571b6a97beffe26bdf564328d50f9123f27e3d3135a7c
|
|
BLAKE2b-256 checksum How to use checksums |
b4f68870a4432e4f414c2a0c2b4a6e25232846284bf4530a6f172265338fd982
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Security for comuniitaliani 0.22.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.