backports.zoneinfo provides a backport of the `zoneinfo` module from Python 3.9 for users running Python 3.6, 3.7, or 3.8. It offers an efficient, C-based implementation of the `zoneinfo` module, allowing older Python versions to use the standard library's `ZoneInfo` object for handling IANA time zones. The current version is 0.2.1, with releases typically happening as needed for bug fixes or minor enhancements.
pip install backports-zoneinfoVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates importing `ZoneInfo` and using it to create a timezone-aware datetime object. Note that `backports.zoneinfo` provides the API, but relies on system timezone data (e.g., from `/usr/share/zoneinfo` or the `tzdata` package) to resolve timezone names like 'Europe/Paris'.
Always import from `backports.zoneinfo` when targeting Python 3.6-3.8. For Python 3.9+, use `from zoneinfo import ZoneInfo`.
Install the `tzdata` package (`pip install tzdata`) which provides a standard source of timezone data, or ensure your operating system provides `zoneinfo` files (e.g., in `/usr/share/zoneinfo`).
Upgrade to `backports-zoneinfo>=0.2.1` to correctly subclass `ZoneInfo`.
Install build essentials like `gcc` and `python3-dev` (or equivalent for your OS/distribution) in your environment before installing `backports-zoneinfo`. For Debian-based Docker images (like `python:*-slim`), this typically means running `apt-get update && apt-get install -y gcc python3-dev`.
Ensure that build essential packages, including a C compiler, are installed in your environment. For Alpine Linux, use `apk add build-base`. For Debian/Ubuntu-based systems, use `apt-get update && apt-get install build-essential`. For other systems, consult your distribution's package manager for equivalent build tool packages.