Remove pytz dependency in favour of stdlib (PP-3822)#3115
Merged
jonathangreen merged 2 commits intomainfrom Mar 6, 2026
Merged
Remove pytz dependency in favour of stdlib (PP-3822)#3115jonathangreen merged 2 commits intomainfrom
jonathangreen merged 2 commits intomainfrom
Conversation
Since Python 3.9+, the standard library provides datetime.timezone.utc and zoneinfo.ZoneInfo, making pytz unnecessary. This project targets Python 3.12+, so we can safely remove it and use the stdlib equivalents.
Contributor
|
I made a ticket for this the other day, so you might want to reference it: PP-3822. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3115 +/- ##
==========================================
- Coverage 93.22% 93.22% -0.01%
==========================================
Files 491 491
Lines 45364 45357 -7
Branches 6246 6246
==========================================
- Hits 42292 42285 -7
Misses 1984 1984
Partials 1088 1088 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
tdilauro
approved these changes
Mar 6, 2026
Contributor
tdilauro
left a comment
There was a problem hiding this comment.
Looks good! 🚀
I did note that we go back and forth between timezone.utc and datetime.UTC, but I'm assuming that's just to avoid importing datetime when we're already importing some of its members.
2 tasks
jonathangreen
added a commit
to ThePalaceProject/virtual-library-card
that referenced
this pull request
Mar 11, 2026
## Description Remove the `pytz` dependency. `pytz` is no longer recommended for Python 3.9+; the stdlib `zoneinfo` module and `django.utils.timezone` are the preferred alternatives. This codebase already uses `django.utils.timezone` exclusively with no direct imports of `pytz`, so this is a clean removal. ## Motivation and Context This is part of an effort to remove `pytz` across all Palace Project repositories: - ThePalaceProject/circulation#3115 - ThePalaceProject/library-registry#893 - ThePalaceProject/palace-tools#211 ## How Has This Been Tested? Confirmed there are no imports of `pytz` anywhere in the codebase. All timezone handling already uses `django.utils.timezone`. ## Checklist - [x] I have updated the documentation accordingly. - [x] All new and existing tests passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Replace all
pytzusage with Python standard library equivalents (datetime.timezone.utcandzoneinfo.ZoneInfo). Removepytzandtypes-pytzfrom project dependencies.Replacements made
pytzpatternpytz.UTC/pytz.utcdatetime.UTC/datetime.timezone.utcpytz.utc.localize(dt)to_utc(dt)dt.astimezone(pytz.UTC)dt.astimezone(datetime.UTC)pytz.timezone("US/Eastern")zoneinfo.ZoneInfo("US/Eastern")Motivation and Context
pytzis a legacy timezone library. Since Python 3.9+, the standard library providesdatetime.timezone(for UTC) andzoneinfo.ZoneInfo(for named timezones), makingpytzunnecessary. This project targets Python 3.12+, so it can safely be removed, reducing the dependency footprint.JIRA: PP-3822
How Has This Been Tested?
mypy& tests passChecklist