Olson Timezone Database for Python
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.
Warnings
- 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.
- 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.
- 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.
Install
-
pip install pytzdata
Imports
- tz_file
from pytzdata import tz_file
- tz_path
from pytzdata import tz_path
- set_directory
import pytzdata pytzdata.set_directory('/custom/zoneinfo')
Quickstart
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}...")