Skip to main content

A simple timezone lookup by zip code

Project description

zip2tz

Fast, zero-dependency US zip code to timezone lookup for Python.

  • 38,000+ zip codes mapped to IANA timezones
  • Zero dependencies — pure Python, works everywhere
  • O(1) lookup — instant hash table lookups, no database or file I/O
  • Tiny footprint — ~100KB installed, loads in milliseconds
  • Type-annotated — full type hints included

Installation

pip install zip2tz

Or with uv:

uv add zip2tz

Usage

import zip2tz

# Get timezone for a zip code
tz = zip2tz.timezone("90210")
print(tz)  # America/Los_Angeles

tz = zip2tz.timezone("10001")
print(tz)  # America/New_York

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

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

Why zip2tz?

Most timezone lookup libraries require external databases, network calls, or heavy dependencies. zip2tz bakes the data directly into Python bytecode — just import and go.

Feature zip2tz Other libraries
Dependencies 0 Often requires pytz, databases, or APIs
Lookup speed O(1) hash Varies (file I/O, network, etc.)
Install size ~100KB Often MB+
Offline Yes Sometimes requires network

API

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

Returns the IANA timezone string (e.g., "America/New_York") for the given US zip code, or None if not found.

Parameters:

  • zipcode — A 5-digit US zip code as a string or integer

Returns:

  • IANA timezone string, or None if the zip code is not in the database

Coverage

Covers all 50 US states plus DC, including:

  • All continental US timezones
  • Alaska (9 timezones)
  • Hawaii
  • Indiana's complex county-level timezone boundaries
  • North Dakota's split counties

Data Accuracy

This library provides timezone mappings on a best-effort basis. While we strive for accuracy, we make no guarantees that the data is complete or correct. Timezone boundaries can be complex (especially in states like Indiana and Arizona), and zip codes occasionally span multiple timezones.

If you find an incorrect mapping or missing zip code, please open an issue with:

  • The zip code in question
  • The expected timezone
  • A source for the correct mapping (if available)

Contributing

Contributions are welcome! If you'd like to improve the data or code:

  1. Fork the repository
  2. Make your changes
  3. Open a pull request

For data corrections, please include a reliable source for the timezone mapping.

License

MIT License — see LICENSE for details.

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

zip2tz-0.1.4.tar.gz (111.7 kB view details)

Uploaded Source

Built Distribution

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

zip2tz-0.1.4-py3-none-any.whl (103.0 kB view details)

Uploaded Python 3

File details

Details for the file zip2tz-0.1.4.tar.gz.

File metadata

  • Download URL: zip2tz-0.1.4.tar.gz
  • Upload date:
  • Size: 111.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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 zip2tz-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b2affc05ce7b22bf5419b065bba050da3b1bfc2e719d6d37799acc02365bd010
MD5 c89400645ba4df76362bf6e93c258adc
BLAKE2b-256 52a40def4217cbf4c82141e50d4fc1cf76795be98680ed4d955adc7fa90c74e3

See more details on using hashes here.

File details

Details for the file zip2tz-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: zip2tz-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 103.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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 zip2tz-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 db236cef6091e4df9e095eb340ee28708d360b0e245d3cdce1e14f3fd1c094e0
MD5 44f49056c48cacd4ffee1a4f1db786c4
BLAKE2b-256 ecb29862c8ed489df3bc133bf7a3f2c9546c85c5ce7cc10c00ef9df9388f6871

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