{"id":1395,"library":"backports-zoneinfo","title":"Backports ZoneInfo","description":"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.","status":"active","version":"0.2.1","language":"en","source_language":"en","source_url":"https://github.com/pganssle/zoneinfo","tags":["timezone","datetime","backport","iana"],"install":[{"cmd":"pip install backports-zoneinfo","lang":"bash","label":"Install `backports-zoneinfo`"}],"dependencies":[{"reason":"Provides 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.","package":"tzdata","optional":true}],"imports":[{"note":"On Python < 3.9, the built-in `zoneinfo` module does not exist. The backport lives in the `backports.zoneinfo` namespace.","wrong":"from zoneinfo import ZoneInfo","symbol":"ZoneInfo","correct":"from backports.zoneinfo import ZoneInfo"}],"quickstart":{"code":"import datetime\nfrom backports.zoneinfo import ZoneInfo\n\n# Ensure you have timezone data on your system (e.g., via 'pip install tzdata' or system package)\n\ntry:\n    paris_tz = ZoneInfo(\"Europe/Paris\")\n    now_utc = datetime.datetime.now(datetime.timezone.utc)\n    now_paris = now_utc.astimezone(paris_tz)\n    print(f\"UTC time: {now_utc.isoformat()}\")\n    print(f\"Paris time: {now_paris.isoformat()}\")\nexcept Exception as e:\n    print(f\"Error: {e}. Do you have timezone data installed? (e.g. `pip install tzdata`)\")","lang":"python","description":"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'."},"warnings":[{"fix":"Always import from `backports.zoneinfo` when targeting Python 3.6-3.8. For Python 3.9+, use `from zoneinfo import ZoneInfo`.","message":"When 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.","severity":"gotcha","affected_versions":"<3.9"},{"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`).","message":"`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`.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade to `backports-zoneinfo>=0.2.1` to correctly subclass `ZoneInfo`.","message":"An 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.","severity":"breaking","affected_versions":"0.2.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}