Python, starting from version 3.9, makes access to the information regarding current
and historical time zones easier than ever. The Python standard library provides a
zoneinfo module that is an interface to the time zone database either provided by
your operating system or obtained as a first-party tzdata package from PyPI.
tzdata is quite unique because it is maintained by CPython's core
developers. The reason for extracting the contents of the IANA (Internet Assigned Numbers Authority)
database to separate packages on PyPI is to ensure regular updates
that are independent from CPython's release cadence.
The Time Zone Database (often called tz or zoneinfo) contains code and data that represent the history of local time for many representative locations around the globe. It is updated periodically to reflect changes made by political bodies to time zone boundaries, UTC offsets, and daylight-saving rules. Its management procedure is documented in BCP 175: Procedures for Maintaining the Time Zone Database.
from datetime import datetime
from zoneinfo import ZoneInfo
dt = datetime(2022, 1, 12, tzinfo=ZoneInfo("Europe/Berlin"))
Time zoneaware datetime objects are essential in properly calculating the time differences in
specific time zones because they are able to take into account things such as changes
between standard and daylight-saving time, together with any historical changes
made to IANA's time zone database.