Skip to main content

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

Project description

tzfpy

  • PyPI
  • PyPI - Python Version
  • PyPI - Downloads
  • Anaconda-Server Badge
  • Conda Downloads
  • Conda Platform

[!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+.
  6. Try it online: https://ringsaturn.github.io/tzf-web/

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.16.0 on my MacBook Pro with Apple M3 Max.

pytest --benchmark-warmup=on --benchmark-warmup-iterations=100 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     699.9937  7,175.0022  1,562.1433  646.9249  1,441.6990  833.3940  13716;984      640.1461   41026          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.81s):
         1 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.

Contributing

Install:

Available commands:
  build    - Build the project using uv
  fmt      - Format the code using ruff
  lint     - Lint the code using ruff
  sync     - Sync and compile the project using uv
  lock     - Lock dependencies using uv
  upgrade  - Upgrade dependencies using uv
  all      - Run lock, sync, fmt, lint, and test
  test     - Run tests using pytest
make all

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.16.0.tar.gz (38.1 kB view details)

Uploaded Source

Built Distributions

tzfpy-0.16.0-cp39-abi3-win_amd64.whl (6.2 MB view details)

Uploaded CPython 3.9+ Windows x86-64

tzfpy-0.16.0-cp39-abi3-musllinux_1_1_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.9+ musllinux: musl 1.1+ x86-64

tzfpy-0.16.0-cp39-abi3-musllinux_1_1_aarch64.whl (6.5 MB view details)

Uploaded CPython 3.9+ musllinux: musl 1.1+ ARM64

tzfpy-0.16.0-cp39-abi3-manylinux_2_24_armv7l.whl (6.3 MB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.24+ ARMv7l

tzfpy-0.16.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ x86-64

tzfpy-0.16.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.3 MB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ ARM64

tzfpy-0.16.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (12.7 MB view details)

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

File details

Details for the file tzfpy-0.16.0.tar.gz.

File metadata

  • Download URL: tzfpy-0.16.0.tar.gz
  • Upload date:
  • Size: 38.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.7.4

File hashes

Hashes for tzfpy-0.16.0.tar.gz
Algorithm Hash digest
SHA256 4d31b6b893d5edfa3c6cfb9f38f112ed95b4595330a7d2be93a1e7072e255fe1
MD5 b15512b4f1fa000cee4b082d38784d23
BLAKE2b-256 9f31fbb1b3f23d1f66a299f3135d4dcc96774dc023d80a7a496de586bc73c413

See more details on using hashes here.

File details

Details for the file tzfpy-0.16.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: tzfpy-0.16.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 6.2 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.7.4

File hashes

Hashes for tzfpy-0.16.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 63b3602afcaca86972227c92d19537216881219a877082528b183bea2e0dcb63
MD5 1d1311e04611c74ef33f0da261fbe122
BLAKE2b-256 6111be11e3deef41e3c6c1870141cf144f583d33eda3e3d119b478621fc401aa

See more details on using hashes here.

File details

Details for the file tzfpy-0.16.0-cp39-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for tzfpy-0.16.0-cp39-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1638203e8e2001f6c84919c346d8fd0a649c8e72237aa807bae7c5f7ce78a22f
MD5 208d11acfb68678f627aa1b52075f430
BLAKE2b-256 eef66ad518d5183ce742ad85da795d451656c5ba2367a047ea8e5dd836085acc

See more details on using hashes here.

File details

Details for the file tzfpy-0.16.0-cp39-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for tzfpy-0.16.0-cp39-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 24d650ba29309e9848af7c2bc02af4a823e6686198bb50cae8c92cf6b896cb5b
MD5 af2476b202fcdaa4c5c82fac8b2ce84a
BLAKE2b-256 081dddbbdad88d21059babeacf61f23673149a1466a6128afb2583cbf20266d2

See more details on using hashes here.

File details

Details for the file tzfpy-0.16.0-cp39-abi3-manylinux_2_24_armv7l.whl.

File metadata

File hashes

Hashes for tzfpy-0.16.0-cp39-abi3-manylinux_2_24_armv7l.whl
Algorithm Hash digest
SHA256 21d38a6a76a1a5b29d53bed21c2fb27d7f5ea8d0de41c4a33c3e852c25cb9943
MD5 5362dc73de1c1fff8278890c5a726743
BLAKE2b-256 d7645bf9482a676e8dfd726121733d4321550cba177409dcc2248d1bff841764

See more details on using hashes here.

File details

Details for the file tzfpy-0.16.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tzfpy-0.16.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9c9e1286f216d225ab3fdfbcaf0ee006e6235a4abb8b2255a6df699c21ec6b4a
MD5 9c6d672193abaed0d488b06cc5583028
BLAKE2b-256 4572e79c653db777f0f6d280fa2e474f98720b27bce623589a96b3bc2b6bd8ec

See more details on using hashes here.

File details

Details for the file tzfpy-0.16.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tzfpy-0.16.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c2481b9a4d545d845c235a56293e14dffdf72342bf9137f810dc5888693b1931
MD5 927bca7defe17ec5a768de339a673680
BLAKE2b-256 ad4dd41e7017ff2ed18b107aed544dcef2dce0dab00b5a431b8e10709fb4a9cd

See more details on using hashes here.

File details

Details for the file tzfpy-0.16.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for tzfpy-0.16.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 518653568af24b7c76c4ec3e279d06a65e034ca23cc06da18f946fc56e0f71bb
MD5 f94066125841194e3cd9e9f91294c605
BLAKE2b-256 bb063734694b66e97fba3155971c69c43cebba39d842d197fa7a3f9e0c4a82c9

See more details on using hashes here.

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