Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

656 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timezonefinder

Coordinate to IANA timezone lookup

Offline timezone lookup for WGS84 coordinates, with no polygon simplification - so the answer stays correct at timezone borders.

https://github.com/jannikmi/timezonefinder/actions/workflows/build.yml/badge.svg?branch=master documentation status pre-commit total PyPI downloads latest version on PyPI latest version on conda-forge supported python versions linted and formatted with ruff

In comparison to other alternatives this package aims at maximum accuracy around timezone borders while offering fast lookup performance and compatibility with many (Python) runtime environments. It combines preprocessed polygon data, H3-based spatial shortcuts, and optional acceleration via Numba or a clang-backed point-in-polygon routine.

Quick Guide

It is recommended to install it together with the optional Numba package for increased performance:

pip install timezonefinder[numba]
# use the global function for convenience:
from timezonefinder import timezone_at

tz = timezone_at(lng=13.358, lat=52.5061)  # 'Europe/Berlin'


# For improved performance and control, create and reuse an instance:
from timezonefinder import TimezoneFinder

tf = TimezoneFinder(in_memory=True)  # reuse

query_points = [(13.358, 52.5061), ...]
for lng, lat in query_points:
    tz = tf.timezone_at(lng=lng, lat=lat)  # 'Europe/Berlin'

Note: This library uses the full original timezone dataset with all >440 timezone names, providing full localization capabilities and historical timezone accuracy. For applications that prefer a smaller memory footprint, the reduced "timezones-now" dataset is available via the update_data.sh script (cf. Documentation).

How it works

A lookup scales the coordinates to 32-bit integers (x 10^7, ~1 cm resolution), finds the point's H3 hexagon at resolution 3, and reads a precomputed shortcut for that cell. Most cells are covered by a single timezone, so the answer is returned immediately with no geometry touched at all. Only an ambiguous cell falls through to the polygons it lists: bounding-box rejection first, then a ray-casting point-in-polygon test - holes before the outer ring, since holes are smaller and can reject the polygon outright.

The central trade-off: the boundary polygons are never simplified, so border accuracy is limited only by the source dataset. The H3 index is what makes carrying full-resolution geometry affordable.

Since the dataset includes ocean zones, every coordinate on earth matches some timezone - use timezone_at_land() when you need to tell land from sea.

Performance

Hundreds of thousands of lookups per second on a single core for uniformly random query points. The exact figure depends on the acceleration backend, the machine and the dataset version, so the benchmark reports below carry it - each states the configuration it was measured in - rather than this page, which would go stale.

The point-in-polygon routine has three interchangeable backends, selected at import time: a clang-compiled C extension (built automatically when a compiler is available), Numba JIT compilation (preferred when the optional dependency is installed), and pure Python. The pure-Python fallback is ~400x slower and always correct - a missing compiler costs speed, never results.

Engineering notes

  • Architecture - the lookup pipeline, the acceleration backends, and the ceilings this package deliberately does not exceed
  • Data Format - binary layouts, coordinate scaling and the H3 index
  • Benchmarking Methodology - the measurement design and where every threshold comes from
  • Testing philosophy - the tests that exist because a rule needed a failure mode, plus the property-based suite and the version/backend matrix
  • How it ships - abi3 wheels, three libc targets, and the checks that stop a broken wheel reaching PyPI
  • Alternatives - the trade-offs against tzfpy, and when to choose it instead
  • Changelog

Alternative: Need maximum speed at the cost of accuracy? Check out tzfpy - a fast and lightweight alternative based on Rust.

Contributing

Looking for maintainers. Reach out if you want to contribute!

Contribution guidelines, the development workflow and the testing/benchmarking gates are documented in CONTRIBUTING.md.

References

LICENSE

timezonefinder is licensed under the MIT license.

The data is licensed under the ODbL license, following the base dataset from evansiroky/timezone-boundary-builder.

About

Offline timezone lookup for WGS84 coordinates, with no polygon simplification - so the answer stays correct at timezone borders.

Topics

Resources

Contributing

Stars

537 stars

Watchers

9 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages