Once you have a decoded coordinate pair, you can resolve it to Panama’s administrative geography: province, district, corregimiento (township), poblado (village), and barrio (neighborhood). TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/kass507/panama-postal/llms.txt
Use this file to discover all available pages before exploring further.
panama_postal_location module provides three locator classes that cover different tradeoffs between speed, offline capability, and simplicity.
Political Division Levels
Panama uses a five-level administrative hierarchy. Each level in the result dict contains anombre (name) and a codigo (identifier code):
None rather than raising an error, so you can safely check each key independently.
The Three Locator Classes
RemoteLocator
Calls the official API endpoint
https://codigospostalespanama.gob.pa/api/location. No local files required. Requires a network connection for every lookup.LocalLocator
Does point-in-polygon against downloaded GeoJSON files. Works fully offline. Returns
None for any level whose file is missing.HybridLocator
Tries local first; falls back to remote if no local data is available. Supports a
prefer parameter for explicit control.Optional GeoJSON Files for Local Lookups
To enable offline resolution, download the boundary files for each political level you need. All files are hosted on the official government site.| File | Level | Name property | ID property |
|---|---|---|---|
PROVINCIAS.geojson.gz | Province | PROV_NOMB | PROV_ID |
DISTRITOS.geojson.gz | District | DIST_NOMB | DIST_ID |
CORREGIMIENTOS.geojson.gz | Corregimiento | CORR_NOMB | CORR_ID |
POBLADOS.geojson.gz | Village | LUPO_NOMB | LUPO_ID |
BARRIOS.geojson.gz | Neighborhood | BARR_NOMB | BARR_ID |
LocalLocator and HybridLocator resolve whichever levels have a corresponding file present and leave the rest as None.
Code Examples
- HybridLocator (recommended)
- RemoteLocator
- LocalLocator
Checking for Local Data
HybridLocator.has_local_data() returns True if at least one of the five GeoJSON boundary files is present in the configured directory. Use this to report data availability to your users or to decide at startup which mode to announce:
LocalLocator.has_any_data() exposes the same check directly on the lower-level class, which is useful when you are using LocalLocator on its own rather than through HybridLocator:
RemoteLocator Timeout
RemoteLocator defaults to a 10-second timeout per request. You can configure this via the constructor:
lookup() returns None rather than raising an exception.
The GeoJSON boundary files are data from Panama’s national statistics institute (INEC) and are not included in the Panama Postal repository. They must be downloaded from the official government site before local lookups are available.