{"id":15472031,"url":"https://github.com/pganssle/pytz-deprecation-shim","last_synced_at":"2025-08-02T01:10:55.446Z","repository":{"id":43188572,"uuid":"271372997","full_name":"pganssle/pytz-deprecation-shim","owner":"pganssle","description":"Shims to help you safely remove pytz","archived":false,"fork":false,"pushed_at":"2022-03-14T15:49:15.000Z","size":192,"stargazers_count":8,"open_issues_count":5,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-17T00:49:39.876Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pganssle.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-10T20:00:06.000Z","updated_at":"2025-01-02T16:49:01.000Z","dependencies_parsed_at":"2022-09-04T05:12:26.505Z","dependency_job_id":null,"html_url":"https://github.com/pganssle/pytz-deprecation-shim","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/pganssle/pytz-deprecation-shim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pganssle%2Fpytz-deprecation-shim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pganssle%2Fpytz-deprecation-shim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pganssle%2Fpytz-deprecation-shim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pganssle%2Fpytz-deprecation-shim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pganssle","download_url":"https://codeload.github.com/pganssle/pytz-deprecation-shim/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pganssle%2Fpytz-deprecation-shim/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268322416,"owners_count":24231819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T02:24:28.619Z","updated_at":"2025-08-02T01:10:55.421Z","avatar_url":"https://github.com/pganssle.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"pytz_deprecation_shim: Shims to help you safely remove pytz\n===========================================================\n\n``pytz`` has served the Python community well for many years, but it is no\nlonger the best option for providing time zones. ``pytz`` has a non-standard\ninterface that is `very easy to misuse\n\u003chttps://blog.ganssle.io/articles/2018/03/pytz-fastest-footgun.html\u003e`_; this\ninterface was necessary when ``pytz`` was created, because ``datetime`` had no\nway to represent ambiguous datetimes, but this was solved in Python 3.6,\nwhich added a ``fold`` attribute to datetimes in `PEP 495\n\u003chttps://www.python.org/dev/peps/pep-0495/\u003e`_. With the addition of the\n``zoneinfo`` module in Python 3.9 (`PEP 615\n\u003chttps://www.python.org/dev/peps/pep-0615/\u003e`_), there has never been a better\ntime to migrate away from ``pytz``.\n\nHowever, since ``pytz`` time zones are used very differently from a standard\n``tzinfo``, and many libraries have built ``pytz`` zones into their standard\ntime zone interface (and thus may have users relying on the existence of the\n``localize`` and ``normalize`` methods); this library provides shim classes\nthat are compatible with both PEP 495 and ``pytz``'s interface, to make it\neasier for libraries to deprecate ``pytz``.\n\nUsage\n=====\n\nThis library is intended for *temporary usage only*, and should allow you to\ndrop your dependency on ``pytz`` while also giving your users notice that\neventually you will remove support for the ``pytz``-specific interface.\n\nWithin your own code, use ``pytz_deprecation_shim.timezone`` shims as if they\nwere ``zoneinfo`` or ``dateutil.tz`` zones — do not use ``localize`` or\n``normalize``:\n\n.. code-block:: pycon\n\n    \u003e\u003e\u003e import pytz_deprecation_shim as pds\n    \u003e\u003e\u003e from datetime import datetime, timedelta\n    \u003e\u003e\u003e LA = pds.timezone(\"America/Los_Angeles\")\n\n    \u003e\u003e\u003e dt = datetime(2020, 10, 31, 12, tzinfo=LA)\n    \u003e\u003e\u003e print(dt)\n    2020-10-31 12:00:00-07:00\n\n    \u003e\u003e\u003e dt.tzname()\n    'PDT'\n\n\nDatetime addition will work `like normal Python datetime arithmetic\n\u003chttps://blog.ganssle.io/articles/2018/02/aware-datetime-arithmetic.html\u003e`_,\neven across a daylight saving time transition:\n\n.. code-block:: pycon\n\n    \u003e\u003e\u003e dt_add = dt + timedelta(days=1)\n\n    \u003e\u003e\u003e print(dt_add)\n    2020-11-01 12:00:00-08:00\n\n    \u003e\u003e\u003e dt_add.tzname()\n    'PST'\n\nHowever, if you have exposed a time zone to end users who are using ``localize``\nand/or ``normalize`` or any other ``pytz``-specific features (or if you've\nfailed to convert some of your own code all the way), those users will see\na warning (rather than an exception) when they use those features:\n\n.. code-block:: pycon\n\n    \u003e\u003e\u003e dt = LA.localize(datetime(2020, 10, 31, 12))\n    \u003cstdin\u003e:1: PytzUsageWarning: The localize method is no longer necessary, as\n    this time zone supports the fold attribute (PEP 495). For more details on\n    migrating to a PEP 495-compliant implementation, see\n    https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html\n\n     \u003e\u003e\u003e print(dt)\n    2020-10-31 12:00:00-07:00\n    \u003e\u003e\u003e dt.tzname()\n    'PDT'\n\n    \u003e\u003e\u003e dt_add = LA.normalize(dt + timedelta(days=1))\n    \u003cstdin\u003e:1: PytzUsageWarning: The normalize method is no longer necessary,\n    as this time zone supports the fold attribute (PEP 495). For more details\n    on migrating to a PEP 495-compliant implementation, see\n    https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html\n\n    \u003e\u003e\u003e print(dt_add)\n    2020-11-01 12:00:00-08:00\n    \u003e\u003e\u003e dt_add.tzname()\n    'PST'\n\nFor IANA time zones, calling ``str()`` on the shim zones (and indeed on ``pytz``\nand ``zoneinfo`` zones as well) returns the IANA key, so end users who would\nlike to actively migrate to a ``zoneinfo`` (or ``backports.zoneinfo``) can do\nso:\n\n.. code-block:: pycon\n\n    \u003e\u003e\u003e from zoneinfo import ZoneInfo\n    \u003e\u003e\u003e LA = pds.timezone(\"America/Los_Angeles\")\n    \u003e\u003e\u003e LA_zi = ZoneInfo(str(LA))\n    \u003e\u003e\u003e print(LA_zi)\n    zoneinfo.ZoneInfo(key='America/Los_Angeles')\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpganssle%2Fpytz-deprecation-shim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpganssle%2Fpytz-deprecation-shim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpganssle%2Fpytz-deprecation-shim/lists"}