timezonefinder is a Python package for efficiently determining the timezone of any geographic point on Earth (given its coordinates) entirely offline. It uses a custom database of timezone polygons. The current stable version is 8.2.2. The library is actively maintained, with significant updates and breaking changes occurring with major version releases, such as v8.0.0 in early 2024.
pip install timezonefinderVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `TimezoneFinder` and use `timezone_at` to find the timezone for specific geographic coordinates. It highlights the use of named arguments for longitude and latitude to avoid common coordinate order mistakes.
Change `from timezonefinder import TimezoneFinderL` to `from timezonefinder import TimezoneFinder`. Ensure 'scipy' is installed (`pip install timezonefinder[full]`) if the faster algorithm is desired.
Remove the `force_reload` parameter from your `TimezoneFinder` initialization calls. The library manages data loading automatically.
If you were using `in_memory`, rename the parameter to `in_memory_threshold` in your `TimezoneFinder` initialization. For example, `TimezoneFinder(in_memory=True)` becomes `TimezoneFinder(in_memory_threshold=1)`.
Always use named arguments `lng=` and `lat=` (e.g., `tf.timezone_at(lng=10.0, lat=50.0)`) to ensure correct coordinate order and improve code readability.
Initialize `TimezoneFinder()` once and reuse the instance throughout your application's lifecycle. Avoid initializing it repeatedly within loops or request handlers.
Install the timezonefinder package using pip. ```bash pip install timezonefinder ```
Import the `TimezoneFinder` class, instantiate it, and then call the `timezone_at()` method on the instance. ```python from timezonefinder import TimezoneFinder tf = TimezoneFinder() timezone = tf.timezone_at(lng=5.0, lat=50.0) ```
Initialize the `TimezoneFinder` object without coordinates and then call `timezone_at()` with the desired longitude and latitude. ```python from timezonefinder import TimezoneFinder tf = TimezoneFinder() tz = tf.timezone_at(lng=5.0, lat=50.0) ```
Instantiate the `TimezoneFinder` class and use its `timezone_at()` method, which handles both land and sea coordinates. ```python from timezonefinder import TimezoneFinder tf = TimezoneFinder() tz = tf.timezone_at(lng=5.0, lat=50.0) ```
Reinstall `timezonefinder` to ensure all data files are correctly downloaded and placed. If running in a custom environment, verify that the `timezonefinder/data` directory exists within your `site-packages`. ```bash pip uninstall timezonefinder pip install timezonefinder ```