Skip to main content

Documentation 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 ships as a set of plain Python source files — no package index, no build step, no virtual environment required. The only prerequisite is Python 3.10 or later. Everything else is Python standard library.
There is no pip install panama-postal. Setup is a single git clone. If Python 3.10+ is available on your system, the library and CLI are ready to use immediately after cloning.

Installation Steps

1
Clone the repository
2
Clone the project from GitHub and change into the project directory:
3
git clone https://github.com/kass507/panama-postal.git
cd panama-postal
4
The four source files — panama_postal.py, panama_postal_estafeta.py, panama_postal_location.py, and panama_postal_cli.py — are all you need to decode, encode, and validate postal codes.
5
Verify your Python version
6
Panama Postal uses match statements and union type hints (X | Y) introduced in Python 3.10. Confirm your version:
7
python --version
# Python 3.10.x or higher required
8
(Optional) Download GeoJSON data files for offline enrichment
9
For offline estafeta lookups and political division resolution, download the government-published GeoJSON files into the project directory:
10
curl -O https://codigospostalespanama.gob.pa/estafeta.geojson.gz
curl -O https://codigospostalespanama.gob.pa/PROVINCIAS.geojson.gz
curl -O https://codigospostalespanama.gob.pa/DISTRITOS.geojson.gz
curl -O https://codigospostalespanama.gob.pa/CORREGIMIENTOS.geojson.gz
curl -O https://codigospostalespanama.gob.pa/POBLADOS.geojson.gz
curl -O https://codigospostalespanama.gob.pa/BARRIOS.geojson.gz
11
Place these files in the same directory as the Python scripts so the library can find them automatically.
12
Verify the setup
13
Run the CLI with a known postal code to confirm everything is working:
14
python panama_postal_cli.py ACC99-PJ42W
15
You should see decoded coordinates, precision level, and — if the GeoJSON files are present — estafeta name and political division data.

GeoJSON Data Files Explained

Each .geojson.gz file serves a distinct enrichment purpose:
FileEnables
estafeta.geojson.gzEstafeta name (ESTAF_NAME), postal zone (VM_LEVEL, VM_LEVEL2D), and service area (AREA) via point-in-polygon lookup
PROVINCIAS.geojson.gzProvince name and code (e.g. PANAMÁ)
DISTRITOS.geojson.gzDistrict name and code (e.g. PANAMÁ)
CORREGIMIENTOS.geojson.gzCorregimiento name and code (e.g. ANCÓN)
POBLADOS.geojson.gzVillage (poblado) name and code
BARRIOS.geojson.gzNeighborhood (barrio) name and code
These files are not bundled in the repository. They are public data published by INEC Panama and downloaded directly from the official government site. Panama Postal does not redistribute them.

What Happens Without the GeoJSON Files

The core codec — decode(), encode(), and validate() — works entirely without GeoJSON files since it is pure arithmetic over a geographic grid. For enrichment data:
  • Estafeta lookups (EstafetaIndex) require estafeta.geojson.gz and will not produce results without it.
  • Political division lookups (HybridLocator) automatically fall back to the official codigospostalespanama.gob.pa/api/location endpoint when local files are absent. An active internet connection is required for the fallback to succeed.
The CLI prints a reminder when estafeta.geojson.gz is not found. You can suppress estafeta and location output entirely with the --no-location flag if you only need coordinates.

Project File Overview

FileDescription
panama_postal.pyCore codec: decode, encode, validate, is_in_panama
panama_postal_estafeta.pyEstafeta lookup via point-in-polygon against estafeta.geojson.gz
panama_postal_location.pyPolitical division lookup — local GeoJSON or remote API fallback
panama_postal_cli.pyCommand-line interface with interactive and batch modes

CLI Flags Reference

FlagEffect
--no-locationSkips province/district lookup — faster, requires no network
--laxoUses the official site’s permissive bounding box for validation instead of the strict territory bbox

Build docs developers (and LLMs) love