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.1.tar.gz (348.0 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.1-py3-none-any.whl (340.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zip2info-1.0.1.tar.gz
  • Upload date:
  • Size: 348.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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.1.tar.gz
Algorithm Hash digest
SHA256 f7deaa64ca8d4e3527c2e63bb9c2cbdbdc6a46596c2231056a48b8cf78184cdf
MD5 65eba2b0706589e2f22f4e1ba1d30bba
BLAKE2b-256 183afea1ae068d883be218b7acf8cad33fe47f3b3cd59501c605d60bd02d42af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zip2info-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 340.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 06464ede3c2f35dcf77fe6c30c42a05f786f3d2842fb5972e14793fa7c57db67
MD5 38b7846493a05f5515481db651f6dea3
BLAKE2b-256 a66d5c40d59b6e7002277c96613bf49f85821ac9cef77b88736697b1ef2070c0

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