Skip to main content

Fast US ZIP code lookups for timezone and geocoordinates

Project description

zip2info

Fast, zero-dependency US ZIP code lookups for Python.

  • 38,000+ zip codes mapped to IANA timezones
  • Geocoordinates for ZIP centroids (latitude/longitude)
  • Zero dependencies — pure Python, works everywhere
  • O(1) lookup — instant hash table lookups, no database or file I/O
  • Type-annotated — full type hints included

Installation

pip install zip2info

Or with uv:

uv add zip2info

Usage

import zip2info

# Timezone lookup
tz = zip2info.timezone("90210")
print(tz)  # America/Los_Angeles

# Coordinate lookup (latitude, longitude)
coords = zip2info.coordinates("90210")
print(coords)  # (34.0901, -118.4065)

# Rich metadata
record = zip2info.info("10001")
print(record.timezone)   # America/New_York
print(record.latitude)   # 40.7484
print(record.longitude)  # -73.9967

# Works with integers too
tz = zip2info.timezone(60601)
print(tz)  # America/Chicago

# Returns None if zip code not found
tz = zip2info.timezone("00000")
print(tz)  # None

API

timezone(zipcode: str | int) -> str | None

Returns the IANA timezone string for a US ZIP code.

coordinates(zipcode: str | int) -> tuple[float, float] | None

Returns (latitude, longitude) for a US ZIP code, or None if unavailable.

info(zipcode: str | int) -> ZipInfo | None

Returns a ZipInfo dataclass with zipcode, timezone, latitude, and longitude. Returns None when timezone or coordinate data is unavailable.

Data sources

  • Timezones: bundled US ZIP-to-timezone dataset (same coverage as the original zip2tz project)
  • Coordinates (merged in priority order):
    1. GeoNames US postal codes (CC BY 4.0)
    2. U.S. Census ZCTA gazetteer centroids (public domain)
    3. Manual overrides in data/coordinate_overrides.json
    4. 3-digit ZIP prefix centroid fallback for remaining USPS-only ZIPs (PO boxes, unique entity codes, etc.)

Regenerate packaged data with:

python scripts/compile_data.py

Migration from zip2tz

zip2info is a new PyPI package and import path. Existing zip2tz installs are unchanged.

# before
import zip2tz
zip2tz.timezone("90210")

# after
import zip2info
zip2info.timezone("90210")

Coverage

Covers all 50 US states plus DC, including Alaska, Hawaii, Indiana county-level boundaries, and other edge cases.

Data accuracy

Timezone and coordinate mappings are provided on a best-effort basis. ZIP codes can span multiple timezones or areas, and coordinate points are centroids/estimates rather than exact address locations.

If you find incorrect data, please open an issue with the ZIP code, expected value, and a source if available.

License

MIT License — see LICENSE for details.

Coordinate data includes GeoNames material licensed under CC BY 4.0.

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

zip2info-1.0.0.tar.gz (346.2 kB view details)

Uploaded Source

Built Distribution

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

zip2info-1.0.0-py3-none-any.whl (340.0 kB view details)

Uploaded Python 3

File details

Details for the file zip2info-1.0.0.tar.gz.

File metadata

  • Download URL: zip2info-1.0.0.tar.gz
  • Upload date:
  • Size: 346.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for zip2info-1.0.0.tar.gz
Algorithm Hash digest
SHA256 46f8a824482d9f638b6e445bb8d40387c556f9ea4a0392b0ffdad507744a173b
MD5 45622f174c0191d14715e3f0e93e7655
BLAKE2b-256 9b42255ee7c72d4ce77332353a6626376dc539a37bb86b28202c821012145c3c

See more details on using hashes here.

File details

Details for the file zip2info-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: zip2info-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 340.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for zip2info-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8cdc2e58f8b1514746bf5ead0e51059486d810a59c8a2fad210bd8f0316390a7
MD5 315271ad2876730b223e3cbb83d54bdc
BLAKE2b-256 e9e78044cc6cb6bc0db2f25644362351a0a2f7c919996bc38ff1c264c312f58c

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