Package: tzfpy
tzfpy[!NOTE]It's probably the fastest Python package to convert longitude/latitude to
timezone name.This package use a simplified polygon data and not so accurate around
borders.Rust use lazy init, so first calling will be a little slow.Use about 40MB memory.It's tested under Python 3.9+ but support 3.7+(noqa).UsagePlease 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 tzfpypipinstalltzfpy# Install tzfpy with pytzpipinstall"tzfpy[pytz]"# Install via conda, see more in https://github.com/conda-forge/tzfpy-feedstockcondainstall-cconda-forgetzfpy>>>fromtzfpyimportget_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']PerformanceBenchmark runs underv0.15.3on my
MacBook Pro with Apple M3 Max.pytesttests/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 passedOr you can view more benchmark results onGitHub Action summary page.Backgroundtzfpywas originally written in Go namedtzfand use CGO compiled to.soto be used by Python. Sincev0.11.0it's rewritten in Rust built on PyO3
andtzf-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 ithere.Project statustzfpyis still under development and it has been deployed intomy 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 packagesPlease note that directly compare with other packages is not fair, because they
have different use cases and design goals, for example, the precise.TimezoneFinderI 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 muchmore widely usedcompared 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.pytzwhereI recommend to read timezonefinder'sComparison to pytzwheresince it's very detailed.LICENSEThis project is licensed under theMIT license. The data is
licensed under theODbL license, same asevansiroky/timezone-boundary-builder