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.2.tar.gz (44.8 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.2-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ziptz_us-0.1.2.tar.gz
  • Upload date:
  • Size: 44.8 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.2.tar.gz
Algorithm Hash digest
SHA256 cfeee63911e601c72ac97a55973b9f0fd538bf4dc4c0207bab2be3901f61665a
MD5 4e35a44b7cd812c1dbc3b0985b69af05
BLAKE2b-256 09506020a2b8268db4d522d6cfea49d1057d537233f3ff5808a9ab554c103a40

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ziptz_us-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 21.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9f4c012acc6f089b174e7d2f03f2921c13354f15e161501a5cb61c82e90f78be
MD5 3c0f15e31a565dc339be66f91e41f2a7
BLAKE2b-256 c1ab66ac2038482c50b87ef14fcaa0b1a19fb09f7b1cc270bf0b2bd95c4f27eb

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 files

0.1.1

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