Skip to main content

Fuzzy and exact lookup tool for Italian municipalities

Project description

🏛️ Municipality Lookup

Municipality Lookup is a lightweight Python library for retrieving information about Italian municipalities (comuni), including province, land registry office, national code, and cadastral code.

It supports both exact and fuzzy search — ideal for OCR scenarios or user input with typos. The official dataset is embedded and loaded automatically.


📦 Installation

Install via pip:

pip install municipality-lookup

🚀 Getting Started

Import and initialize the database using the default embedded CSV:

from municipality_lookup.instance import get_db

# Load the built-in database
db = get_db()

🔍 Search for a Municipality

# Exact match (case-insensitive)
result = db.get_by_name("ABANO TERME")
print(result)
# ➜ Municipality(name='ABANO TERME', province='PD', ...)

✨ Fuzzy search (handles typos or OCR noise)

# Typo-tolerant search
result = db.get_by_name("abno terme")
print(result)

You can customize the minimum similarity score (default is 0.8) and choose between:

  • fast=True (default): faster search using RapidFuzz internals
  • fast=False: slower but more controllable logic with combined ratio + partial_ratio
# Custom fuzzy search
result = db.get_by_name("abano trm", min_score=0.7, fast=False)

📋 Explore the Dataset

# List all province codes
print(sorted(db.get_all_provinces()))

# List all land registry offices
print(sorted(db.get_all_land_registries()))

🔄 Update the Database with a Custom CSV

You can replace the internal dataset with a custom file (same structure as the built-in one):

db.update_database("path/to/your_custom_comuni.csv")

📄 CSV Structure

Custom CSVs must have the following columns (case-sensitive headers):

Column Description
Comune Municipality name (string)
Provincia Province code (e.g. "PD")
Conservatoria di Competenza Land registry office
Codice Nazionale National municipality code (4 chars)
Codice Catastale Cadastral code (4 chars)

✅ Example:

Comune,Provincia,Conservatoria di Competenza,Codice Nazionale,Codice Catastale
ABANO TERME,PD,Padova,A001,D3AB
ABBADIA CERRETO,LO,Lodi,A004,C1AB

➡️ Rows with missing or invalid fields may be ignored or raise errors.


📚 Data Source

The default dataset is based on publicly available information from:

🔗 visurasi.it – Elenco conservatorie e comuni


🧠 Advanced

You can use find_exact(), find_similar(), or find_similar_fast() directly if needed, via:

from municipality_lookup.search import MunicipalitySearcher

📜 License

MIT © Andrea Iannazzo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

municipality_lookup-0.2.2.tar.gz (109.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

municipality_lookup-0.2.2-py3-none-any.whl (108.0 kB view details)

Uploaded Python 3

File details

Details for the file municipality_lookup-0.2.2.tar.gz.

File metadata

  • Download URL: municipality_lookup-0.2.2.tar.gz
  • Upload date:
  • Size: 109.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.0

File hashes

Hashes for municipality_lookup-0.2.2.tar.gz
Algorithm Hash digest
SHA256 04e99b0a5fc89d664f5c1e6d90d9db167c63d311c800b9866400fe89c8e3c76f
MD5 586d3a1773a0b88fb98d6df3896e9567
BLAKE2b-256 e80a805624888d41455263e094dfa28db6e1ccff1829f9733eaeb14869c772c1

See more details on using hashes here.

File details

Details for the file municipality_lookup-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for municipality_lookup-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c25a50007fcd48c57b51e7ebcd71e1279b435e59a8e192a1619a9ef11e22e531
MD5 145a35037c2e483952f18d872acd1e00
BLAKE2b-256 915d04468e6352aaca69e7f7a1b381aaa992128747f8d8831160f5f97c851f8c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page