pytz: Python’s IANA Gateway

Published: April 5, 2026 | Category: Programming Libraries

Before Python 3.9 introduced the native `zoneinfo` module, **pytz** was the standard way to handle timezones in Python. It brought the IANA (Olson) timezone database to the fingertips of every Python developer.

The Problem with localize()

One of the most famous quirks of pytz is that you cannot simply pass a timezone object to the native `datetime` constructor. Doing so often results in incorrect offsets (like the infamous "LMT" offset). Instead, you must use the `timezone.localize(dt)` method to properly attach a timezone to a "naive" datetime object.

The World of Ambiguity

Handling "ambiguous" times—such as the hour that repeats during the transition from Daylight Saving Time back to Standard Time—is where pytz shines. It allows developers to specify whether a timestamp belongs to the first or second instance of that hour, a level of detail that many other libraries ignore.

The Legacy in Django

The Django web framework relied on pytz for its robust timezone support for over a decade. Even as the Python core library has improved, millions of legacy applications continue to use pytz because of its proven reliability and comprehensive database.

Conclusion

pytz was the library that forced Python developers to be honest about the complexity of time. On the Epoch Clock, we deal in the universal second, but pytz is the tool that tells us exactly which second it was in the streets of Chicago or the offices of Tokyo.