Olson Timezone Database for Python

raw JSON →
2020.1 verified Tue May 12 auth: no python install: verified maintenance

pytzdata is a Python library that provides access to the IANA/Olson timezone database files. It packages a snapshot of this database, allowing applications to retrieve raw timezone definitions. The current version, 2020.1, was released in July 2020. The project does not appear to follow a regular release cadence and is effectively in maintenance mode, largely superseded by the standard library `zoneinfo` module in Python 3.9+ and the `tzdata` package.

pip install pytzdata
error ModuleNotFoundError: No module named 'pytzdata'
cause The `pytzdata` library has not been installed in your current Python environment.
fix
pip install pytzdata
error AttributeError: module 'pytzdata' has no attribute 'timezone'
cause You are attempting to use a method (`timezone`) that is part of the `pytz` library (or `zoneinfo` in Python 3.9+), not `pytzdata`. `pytzdata` provides the raw timezone data files, not direct timezone objects for `datetime` manipulation.
fix
To create timezone-aware datetime objects, use pytz (import pytz; tz = pytz.timezone('Europe/London')) or the standard library zoneinfo (from zoneinfo import ZoneInfo; tz = ZoneInfo('Europe/London')).
error FileNotFoundError: [Errno 2] No such file or directory: '.../pytzdata/zones/Continent/NonExistentCity'
cause The requested timezone name either does not exist in the `pytzdata` database, is misspelled, or the internal path to the data files is incorrect.
fix
Verify the correct spelling of the timezone name (e.g., 'Europe/London'). You can use pytzdata.get_all_timezones() to list all available timezone names.
error ModuleNotFoundError: No module named 'pytzdata.tzdata'
cause You are attempting to import `tzdata` as a submodule of `pytzdata`, which does not exist. This might stem from confusion with the separate `tzdata` package or how `pytz` organizes its data.
fix
To access pytzdata functionality, import the main pytzdata module directly (import pytzdata). If you intended to use the separate tzdata package, ensure it is installed (pip install tzdata) and import it as import tzdata.
deprecated The `pytzdata` package itself has not been updated since July 2020. For new projects on Python 3.9 and later, the standard library's `zoneinfo` module, typically combined with the `tzdata` PyPI package, is the recommended and more up-to-date solution for timezone handling.
fix For Python 3.9+, use `from zoneinfo import ZoneInfo` and `pip install tzdata`. For older Python versions requiring external timezone libraries, consider `dateutil.tz` or pinning `pytzdata` and `pytz` to known working versions while being aware of potential data staleness.
gotcha pytzdata only provides the raw IANA/Olson timezone *data files*. It does not provide `tzinfo` objects for direct use with Python's `datetime` module. Libraries like `pytz` (which historically used `pytzdata`'s format) or `zoneinfo` are required to create timezone-aware `datetime` objects.
fix To create timezone-aware `datetime` objects, use `pytz.timezone('Europe/Paris')` (for `pytz`) or `ZoneInfo('Europe/Paris')` (for `zoneinfo` with Python 3.9+ and `tzdata` installed). Do not attempt to use `pytzdata` imports directly as `tzinfo` objects.
gotcha Due to its last release being in 2020, the timezone data bundled with `pytzdata` (version 2020.1) may be outdated. IANA Time Zone Database rules are updated periodically, and `pytzdata` will not reflect these changes without a new release.
fix Ensure your timezone data is current. If using Python 3.9+, prefer `zoneinfo` with `tzdata`, which is updated more frequently. If you must use `pytzdata`, be aware that recent changes to daylight saving rules or geopolitical timezone changes might not be reflected.
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.00s 20.5M
3.10 alpine (musl) - - 0.00s 20.5M
3.10 slim (glibc) wheel 1.6s 0.00s 21M
3.10 slim (glibc) - - 0.00s 21M
3.11 alpine (musl) wheel - 0.00s 22.3M
3.11 alpine (musl) - - 0.00s 22.3M
3.11 slim (glibc) wheel 1.7s 0.00s 23M
3.11 slim (glibc) - - 0.00s 23M
3.12 alpine (musl) wheel - 0.00s 14.2M
3.12 alpine (musl) - - 0.00s 14.2M
3.12 slim (glibc) wheel 1.5s 0.00s 15M
3.12 slim (glibc) - - 0.00s 15M
3.13 alpine (musl) wheel - 0.00s 14.0M
3.13 alpine (musl) - - 0.00s 13.8M
3.13 slim (glibc) wheel 1.5s 0.00s 14M
3.13 slim (glibc) - - 0.00s 14M
3.9 alpine (musl) wheel - 0.00s 20.0M
3.9 alpine (musl) - - 0.00s 20.0M
3.9 slim (glibc) wheel 1.8s 0.00s 20M
3.9 slim (glibc) - - 0.00s 20M

Demonstrates how to retrieve the file path for a timezone or access its raw content using `tz_path` and `tz_file`.

from pytzdata import tz_path

# Get the path to a specific timezone file
paris_tz_path = tz_path('Europe/Paris')
print(f"Path to Europe/Paris timezone data: {paris_tz_path}")

from pytzdata import tz_file

# Access the content of a specific timezone file
with tz_file('America/New_York') as f:
    content_start = f.read(50)
    print(f"First 50 bytes of America/New_York data: {content_start}...")