Skip to main content

ziptz

US ZIP code to IANA time zone, from about 1.3 KB of tables. No dependencies, no data files, no network: the tables are string constants in the source, and the first lookup unpacks them into a dict, so a lookup is a hash.

pip install ziptz-us          # the module is ziptz
>>> import ziptz
>>> ziptz.zone("94110")
'America/Los_Angeles'
>>> ziptz.location("10001")
zoneinfo.ZoneInfo(key='America/New_York')
>>> ziptz.abbrev("94110")      # at an instant you pass, or now
'PDT'
>>> ziptz.generic("94110")     # the same zone, daylight saving left out
'PT'

The distribution is ziptz-us and the module is ziptz, the same split as python-dateutil and dateutil: the bare name on PyPI is a 2013 registration with no files attached, and -us is in any case accurate for something that resolves US ZIP codes and nothing else.

Accuracy

Five digits are exact. Three — the prefix alone — give the majority zone for that prefix, right for 33,558 of the 33,791 ZIP codes and wrong for the 233 that sit on the losing side of a boundary their prefix has to round across.

ziptz.zone("79835")   # America/Denver  — Canutillo, TX; five digits are exact
ziptz.zone("798")     # America/Chicago — the prefix rounds to the majority

It covers the places a US-only table usually forgets — Puerto Rico, the Virgin Islands, Guam, the Northern Marianas, American Samoa — and it answers a 3-digit prefix on its own, which is what you have when an address is half filled in.

Three things to know before depending on it:

  • It is not a ZIP validator. A five-digit code with an assigned prefix always gets an answer, whether or not the Postal Service ever issued it. An error means "no such prefix", never "no such ZIP".
  • Zone names are coarser than the tz database's. About 34 IANA zones fold onto the 11 that agree with them today, so a ZIP in Knox County, Indiana answers America/New_York rather than America/Indiana/Knox. The clock is right; the name is less specific.
  • PO-box and single-building ZIPs have no delivery area in the source data and fall back to their prefix. Where a whole prefix is nothing but those, there is nothing to fall back to and the lookup is an error — 00501 (Holtsville, NY) is the named case.

The tables carry today's zone names, not today's offsets. Daylight saving comes from whatever tzdata the machine has, so a rule change needs no release here — and the tables are wrong for historical dates, since several places have changed zone and these record only where each ZIP is now.

Typed, ships py.typed, and supports Python 3.9 and up. Every answer is checked against a second independent implementation of the same tables — all 101,000 tokens, on every build — so "the two agree" is a build step rather than a claim.

MIT licensed. The tables derive from US Census ZCTA centroids (public domain) resolved through timezone-boundary-builder (ODbL); the NOTICE file shipped in this distribution carries that attribution and should travel with any copy.

Full documentation, the accuracy notes in depth, and the source: https://github.com/choey/ziptz

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ziptz_us-0.1.1.tar.gz (43.3 kB view details)

Uploaded Source

Built Distribution

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

ziptz_us-0.1.1-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file ziptz_us-0.1.1.tar.gz.

File metadata

  • Download URL: ziptz_us-0.1.1.tar.gz
  • Upload date:
  • Size: 43.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ziptz_us-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e188658d52ef570a35820e03bab95dd317e8c135babff92682077c15e4832ed6
MD5 70ceeecd614965cffd7ca2bbf855bac3
BLAKE2b-256 3aa999ed0b5ad8bfd10529da93b06273960ef41f2aa144d8a86dd2f13d2cbe08

See more details on using hashes here.

File details

Details for the file ziptz_us-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ziptz_us-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ziptz_us-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df0fae8205d21996db3fc8a871bdf27967df8662f8996b57b09888e592126167
MD5 417b59ee310c944c82f98812f2605f7b
BLAKE2b-256 0ce9edea108753dc3d128ed7bafcb007bf0e662e22460e07e7dde2408869ed22

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

This release

0.1.1 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page