tzwhere

3.0.3 · maintenance · verified Thu Apr 16

tzwhere (also referred to as pytzwhere) is a Python library designed to look up the timezone for a given latitude and longitude entirely offline. The current version, 3.0.3, released in August 2017, focuses on improving how it handles 'holes' within timezone polygons. It is a mature library, but its data sources and development are not as current as some alternatives.

Common errors

Warnings

Install

Imports

Quickstart

Initialize the tzwhere object once to load timezone data. Then, use the `tzNameAt` method with latitude and longitude to find the corresponding IANA timezone name. The `forceTZ=True` parameter can be used to find the closest timezone even if the point falls outside strict polygon boundaries.

from tzwhere import tzwhere

# Initialize the tzwhere object (loads data into memory)
tz = tzwhere.tzwhere()

# Look up timezone for specific coordinates (e.g., Chicago)
latitude = 35.29
longitude = -89.66
tz_name = tz.tzNameAt(latitude, longitude)
print(f"Timezone at ({latitude}, {longitude}): {tz_name}")

# Example with a point outside a strict boundary, using forceTZ
latitude_ocean = 53.68
longitude_ocean = -6.24 # Near Dublin, Ireland, possibly in water
tz_name_forced = tz.tzNameAt(latitude_ocean, longitude_ocean, forceTZ=True)
print(f"Timezone (forced) at ({latitude_ocean}, {longitude_ocean}): {tz_name_forced}")

view raw JSON →