Helper functions

This module contains helper functions to ease the transition from pytz to another PEP 495-compatible library.


Check if a time zone is a pytz time zone.

This will only import pytz if it has already been imported, and does not rely on the existence of the localize or normalize methods (since the shim classes also have these methods, but are not pytz zones).


Convert a pytz or shim timezone into its modern equivalent.

The shim classes are thin wrappers around zoneinfo or implementations of the datetime.tzinfo base class. This function removes the shim and returns the underlying “upgraded” time zone.

When passed a pytz zone (not a shim), this returns the non-pytz equivalent. This may fail if pytz is using a data source incompatible with the upgraded provider’s data source, or if the pytz zone was built from a file rather than an IANA key.

When passed an object that is not a shim or a pytz zone, this returns the original object.


tz – A datetime.tzinfo object.


KeyError – If a pytz zone is passed to the function with no equivalent in the PEP 495-compatible library’s version of the Olson database.


A PEP 495-compatible equivalent of any pytz or shim class, or the original object.