Registry / serialization / backports-zoneinfo

backports-zoneinfo

JSON →
library0.2.1pypypiunverified

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-zoneinfo
INSTALL
IMPORT
SIG · BACKPORTS-ZONEINFO
B
backports-zoneinfo
serializationpythonv0.2.1
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ZoneInfo
from backports.zoneinfo import ZoneInfo
from zoneinfo import ZoneInfo
On Python < 3.9, the built-in `zoneinfo` module does not exist. The backport lives in the `backports.zoneinfo` namespace.

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'.

import datetime from backports.zoneinfo import ZoneInfo # Ensure you have timezone data on your system (e.g., via 'pip install tzdata' or system package) try: paris_tz = ZoneInfo("Europe/Paris") now_utc = datetime.datetime.now(datetime.timezone.utc) now_paris = now_utc.astimezone(paris_tz) print(f"UTC time: {now_utc.isoformat()}") print(f"Paris time: {now_paris.isoformat()}") except Exception as e: print(f"Error: {e}. Do you have timezone data installed? (e.g. `pip install tzdata`)")
Debug
Known issues
gotchaWhen using `backports-zoneinfo` on Python versions older than 3.9, the correct import path is `from backports.zoneinfo import ZoneInfo`. Using `from zoneinfo import ZoneInfo` will result in an `ImportError` because the `zoneinfo` module is not built-in.
fix
Always import from `backports.zoneinfo` when targeting Python 3.6-3.8. For Python 3.9+, use `from zoneinfo import ZoneInfo`.
affects: <3.9
gotcha`backports.zoneinfo` only provides the `ZoneInfo` API; it does not bundle timezone data itself. You must ensure that timezone data (e.g., IANA Time Zone Database) is available on your system for `ZoneInfo` to correctly resolve timezone names. Without this data, `ZoneInfo("America/New_York")` will raise a `ZoneInfoNotFoundError`.
fix
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`).
affects: All
breakingAn issue in version 0.2.0 caused `ZoneInfo.__init_subclass__` to not be a classmethod, leading to errors when attempting to subclass `ZoneInfo` directly. This was fixed in version 0.2.1.
fix
Upgrade to `backports-zoneinfo>=0.2.1` to correctly subclass `ZoneInfo`.
affects: 0.2.0
gotchaInstalling `backports-zoneinfo` requires a C compiler (e.g., `gcc`) to build its C extensions. Minimal environments like `python:*-slim` Docker images often lack a compiler, leading to build failures. Ensure a C compiler and Python development headers are available in your environment.
fix
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`.
affects: All
breakingBuilding the `backports-zoneinfo` package requires a C compiler (e.g., GCC) to compile its C extension module. On minimal operating system images (like Alpine Linux), build tools are often not pre-installed, leading to build failures during `pip install`. This is a common issue for Python packages with C extensions in constrained environments.
fix
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.
affects: All
Upgrade
Version history
0.2.1latest on PyPI · released Jun 23, 2020
Audit
Dependencies
tzdataoptionalProvides actual IANA timezone data (e.g., 'America/New_York') which `ZoneInfo` relies on. While not a direct PyPI dependency, it's essential for `ZoneInfo` to resolve timezone names.
Agent activity
37 hits · last 30 days
node
32
OpenAI (training)
1
Resources
backports-zoneinfo — pip install backports-zoneinfo · libregistry