Skip to main content

Probably the fastest Python package to convert longitude/latitude to timezone name

Project description

tzfpy PyPI Anaconda-Server Badge

[!NOTE]

  1. It's probably the fastest Python package to convert longitude/latitude to timezone name.
  2. This package use a simplified polygon data and not so accurate around borders.
  3. Rust use lazy init, so first calling will be a little slow.
  4. Use about 40MB memory.
  5. It's tested under Python 3.9+ but support 3.8+(noqa).

Usage

Please note that new timezone names may be added to tzfpy, which could be incompatible with old version package like pytz. As an option, tzfpy supports install compatible version of those packages with extra params.

# Install just tzfpy
pip install tzfpy

# Install tzfpy with pytz
pip install "tzfpy[pytz]"

# Install via conda, see more in https://github.com/conda-forge/tzfpy-feedstock
conda install -c conda-forge tzfpy
>>> from tzfpy import get_tz, get_tzs
>>> get_tz(116.3883, 39.9289)  # in (longitude, latitude) order.
'Asia/Shanghai'
>>> get_tzs(87.4160, 44.0400)  # in (longitude, latitude) order.
['Asia/Shanghai', 'Asia/Urumqi']

Performance

Benchmark runs under v0.15.3 on my MacBook Pro with Apple M3 Max.

pytest tests/test_bench.py
------------------------------------------------------------ benchmark: 1 tests ------------------------------------------------------------
Name (time in ns)                 Min          Max        Mean    StdDev      Median         IQR  Outliers  OPS (Kops/s)  Rounds  Iterations
--------------------------------------------------------------------------------------------------------------------------------------------
test_tzfpy_random_cities     837.4918  11,183.2982  1,973.3456  833.9543  1,820.9103  1,066.7020  6422;511      506.7536   20000          10
--------------------------------------------------------------------------------------------------------------------------------------------

Legend:
  Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
  OPS: Operations Per Second, computed as 1 / Mean
Results (1.95s):
         4 passed

Or you can view more benchmark results on GitHub Action summary page.

Background

tzfpy was originally written in Go named tzf and use CGO compiled to .so to be used by Python. Since v0.11.0 it's rewritten in Rust built on PyO3 and tzf-rs, a tzf's Rust port.

I have written an article about the history of tzf, its Rust port, and its Rust port's Python binding; you can view it here.

Project status

tzfpy is still under development and it has been deployed into my current company's production environment and it works well under high concurrency for weather API and location related data processed. So I think it's ready to be used in production with caution.

I haven't release the v1.0.0 yet and I will try my best to keep current API as stable as possible(only 3 functions). I'm still working on performance improvements on Rust side, which is a release blocker for both tzf-rs and tzfpy.

Compare with other packages

Please note that directly compare with other packages is not fair, because they have different use cases and design goals, for example, the precise.

TimezoneFinder

I got lots of inspiration from it. Timezonefinder is a very good package and it's mostly written in Python, so it's easy to use. And it's much more widely used compared with tzfpy if you care about that.

However, it's slower than tzfpy, especially around the borders, and I have lots of API requests from there. That's the reason I created tzf originally. And then tzf-rs and tzfpy.

pytzwhere

I recommend to read timezonefinder's Comparison to pytzwhere since it's very detailed.

LICENSE

This project is licensed under the MIT license. The data is licensed under the ODbL license, same as evansiroky/timezone-boundary-builder

Project details


Download files

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

Source Distribution

tzfpy-0.15.5.tar.gz (15.4 kB view hashes)

Uploaded Source

Built Distributions

tzfpy-0.15.5-cp312-none-win_amd64.whl (6.2 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

tzfpy-0.15.5-cp312-cp312-musllinux_1_1_x86_64.whl (7.2 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

tzfpy-0.15.5-cp312-cp312-musllinux_1_1_aarch64.whl (7.2 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ ARM64

tzfpy-0.15.5-cp312-cp312-manylinux_2_24_armv7l.whl (7.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.24+ ARMv7l

tzfpy-0.15.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

tzfpy-0.15.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

tzfpy-0.15.5-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (12.7 MB view hashes)

Uploaded CPython 3.12 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

tzfpy-0.15.5-cp311-none-win_amd64.whl (6.2 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

tzfpy-0.15.5-cp311-cp311-musllinux_1_1_x86_64.whl (7.2 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

tzfpy-0.15.5-cp311-cp311-musllinux_1_1_aarch64.whl (7.2 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

tzfpy-0.15.5-cp311-cp311-manylinux_2_24_armv7l.whl (7.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.24+ ARMv7l

tzfpy-0.15.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

tzfpy-0.15.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

tzfpy-0.15.5-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (12.7 MB view hashes)

Uploaded CPython 3.11 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

tzfpy-0.15.5-cp310-none-win_amd64.whl (6.2 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

tzfpy-0.15.5-cp310-cp310-musllinux_1_1_x86_64.whl (7.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

tzfpy-0.15.5-cp310-cp310-musllinux_1_1_aarch64.whl (7.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

tzfpy-0.15.5-cp310-cp310-manylinux_2_24_armv7l.whl (7.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.24+ ARMv7l

tzfpy-0.15.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

tzfpy-0.15.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

tzfpy-0.15.5-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (12.7 MB view hashes)

Uploaded CPython 3.10 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

tzfpy-0.15.5-cp39-none-win_amd64.whl (6.2 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

tzfpy-0.15.5-cp39-cp39-musllinux_1_1_x86_64.whl (7.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

tzfpy-0.15.5-cp39-cp39-musllinux_1_1_aarch64.whl (7.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

tzfpy-0.15.5-cp39-cp39-manylinux_2_24_armv7l.whl (7.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.24+ ARMv7l

tzfpy-0.15.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

tzfpy-0.15.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

tzfpy-0.15.5-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (12.7 MB view hashes)

Uploaded CPython 3.9 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

tzfpy-0.15.5-cp38-none-win_amd64.whl (6.2 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

tzfpy-0.15.5-cp38-cp38-musllinux_1_1_x86_64.whl (7.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

tzfpy-0.15.5-cp38-cp38-musllinux_1_1_aarch64.whl (7.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

tzfpy-0.15.5-cp38-cp38-manylinux_2_24_armv7l.whl (7.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.24+ ARMv7l

tzfpy-0.15.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

tzfpy-0.15.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

tzfpy-0.15.5-cp38-cp38-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (12.7 MB view hashes)

Uploaded CPython 3.8 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page