openedx / openedx/openedx-platform

Remove the deprecated pytz package

Open
#33,980 10 comments 0 reactions 2 assignees View on GitHub

@ttak-apphelix is already working on this.

Since Jul 29, 2025.

Dominant language
Python
Stars
8.2k
Forks
4.4k
Avg merge
6d 18h
Merged PRs (30d)
42

Description

Description

  • pytz got deprecated in Django 4.0 && has been completely removed in Django 5.0.
  • Django 4.2 had provided USE_DEPRECATED_PYTZ flag for pytz support which has now been completely removed in Django 5.0 as well.
  • Django now uses zoneinfo by default and datetime module use this under the hood now instead of pytz

Difference between datetime.timezone and zoneinfo

datetime.timezone and the zoneinfo package are both related to handling time zones in Python, but they serve slightly different purposes and have different use cases.

datetime.timezone
  • This is part of the standard library in Python.
  • It provides a simple way to represent a fixed offset from UTC (Coordinated Universal Time).
  • It doesn't have information about daylight saving time (DST) or historical changes in time zones.
  • It's suitable for scenarios where you only need to work with a constant offset, and historical changes in time zones are not important.
zoneinfo
  • The zoneinfo package is introduced in Python 3.9 as part of PEP 615.
  • It provides a more comprehensive and accurate way to handle time zones by including historical changes, daylight saving time transitions, and more.
  • It uses the IANA Time Zone Database, which is regularly updated to reflect changes in time zones around the world.
  • This package is suitable for applications that require precise handling of time zones, especially when dealing with historical dates.
pytz usages to replace
  • import pytz → 268 files in openedx/edx-platform.
  • pytz.UTC → 97 files in openedx/edx-platform.

Potential Solution

Approach 01 (OUTDATED)

  • Replace pytz.UTC with backports.zoneinfo.UTC
  • Migrate to Python>3.9
  • Replace backports.zoneinfo with zoneinfo

Approach 02

  • Upgrade from Python 3.8 to Python 3.9
  • Replace pytz.UTC with zoneinfo.UTC
Post Django 5.2 update

Edx-platform is already on Django 5.2 and all compatibility issues have already been resolved, even though the platform still relies pytz. Continued work to remove pytz will help remove an unnecessary dependency, following the recommendation in the pytz README:

Projects using Python 3.9 or later should be using the support now included as part of the standard library, and third party packages work with it such as tzdata. pytz offers no advantages beyond backwards compatibility with code written for earlier versions of Python.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.