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.1.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.1-py3-none-any.whl (23.1 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: area_code_locator-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 e01c3a9ad02074e3db63ec6fd42b32d3b515391dcc84c6d5298ecba4857e8f21
MD5 e46614e175eddf3bbf4ce5eb3bec20cb
BLAKE2b-256 2447e5f0a3961996b2c919300bad03972f5c9b9848dddceb81fc8c32baa37c7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for area_code_locator-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2c54c2dc29e98653104f64aa92d4c7f1ece33a6ab85cd67c84207587c151ecb
MD5 9dfc60ea7094757e27b03441f3e54157
BLAKE2b-256 a95dc21661a63d2c66c84cb837e69342b97f4df3eb31b9fe4283d8b6049bc2e2

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