Skip to main content

Reverse-geocode latitude/longitude to NANP (North American) telephone area codes

Project description

NANP Area Code Locator

PyPI version Python versions License: MIT

Reverse-geocode latitude/longitude to NANP telephone area codes. Works offline; ships a compact Parquet of polygons.


✨ Features

  • 🔎 Reverse-geocode (lat, lon) → area code(s)
  • Fast local lookups (vectorized GeoPandas + spatial index)
  • 🪪 NANP coverage (US, Canada, participating Caribbean)
  • 🧳 Zero setup — packaged Parquet data included (~29 MB)
  • 🧭 CRS handled automatically (WGS84 in / projected out as needed)
  • 🧵 Simple API & CLI (lookup() and area-code-lookup)

📦 Install

pip install area-code-locator

# From source:
git clone https://github.com/Eat-A-Fish/area-code-locator.git
cd area-code-locator
pip install -e .

🚀 Quickstart

from area_code_locator import lookup, batch_lookup

# Single point (returns all matching/overlay codes by default)
codes = lookup(40.7128, -74.0060)      # NYC
print(codes)                           # -> ['212', '646', '917', ...]

# First/primary only
code = lookup(34.0522, -118.2437, return_all=False)  # LA
print(code)                              # -> '213'

# Batch
points = [(40.7128, -74.0060), (41.8781, -87.6298)]
print(batch_lookup(points))              # -> [['212', ...], ['312', ...]]

🖥️ CLI

area-code-lookup --lat 40.7128 --lon -74.0060
# -> 917

area-code-lookup --lat 40.7128 --lon -74.0060 --all
# -> ["212", "646", "917", ...]

🧪 API

lookup(lat: float, lon: float, return_all: bool = True) -> Union[str, List[str]]
batch_lookup(points: List[Tuple[float, float]], return_all: bool = True) -> List[Union[str, List[str]]]
  • return_all=True → all matching/overlay area codes
  • return_all=False → first/primary area code

Advanced

from area_code_locator import AreaCodeLocator

loc = AreaCodeLocator()                       # uses bundled data
loc_custom = AreaCodeLocator("path/to/area-codes.parquet")
loc.lookup(40.7128, -74.0060, return_all=True)

🗺️ Data

The package includes a preprocessed Parquet file of area-code polygons, so no setup is required.

Using your own data:

  • Parquet with a polygon geometry column
  • An area-code column named one of: area_code, areacode, npa, or code
  • CRS: EPSG:4326 (WGS84)

🛠️ Development

pip install -e ".[dev]"
pytest

🙏 Acknowledgments

Area-code boundaries derived from public NANP datasets (e.g., projects compiling NANP polygons). Thanks to the open geospatial community for GeoPandas/Shapely/PyProj.


📄 License

MIT © Area Code Locator Contributors

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

area_code_locator-0.2.0.tar.gz (23.1 MB view details)

Uploaded Source

Built Distribution

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

area_code_locator-0.2.0-py3-none-any.whl (23.1 MB view details)

Uploaded Python 3

File details

Details for the file area_code_locator-0.2.0.tar.gz.

File metadata

  • Download URL: area_code_locator-0.2.0.tar.gz
  • Upload date:
  • Size: 23.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for area_code_locator-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c2834f69bd03d7de95c985a8a83fa161d18f3e717b207f1edeb58e39adbb70ff
MD5 b87f1921fa0b6b9e688147cfc3a1ff35
BLAKE2b-256 be741af3a3113e1022cfee146fc436810e9efb8b46ca81bf2649b93a095b4694

See more details on using hashes here.

File details

Details for the file area_code_locator-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for area_code_locator-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a6ee9838885f5a701a3fa5eb316b54f0cf8d0ca2ef85c2818123942e7475547c
MD5 73f9bd9589e9d02999184109f19bf158
BLAKE2b-256 b443f5f7acd0ed691aef9468ac279110946408a2359c84af22a6011d7f241c71

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