← All recipes
Moderne licensed

Replace datetime.utcfromtimestamp() with datetime.fromtimestamp(ts, UTC)

Recipe IDorg.openrewrite.python.migrate.ReplaceDatetimeUtcFromTimestampArtifactopenrewrite-migrate-python

The datetime.utcfromtimestamp() method is deprecated in Python 3.12. Replace it with datetime.fromtimestamp(ts, UTC), importing UTC from datetime where the name is not already in scope. The result is timezone-aware where utcfromtimestamp() was naive, so stored or compared values may need migrating alongside the call sites.

Single recipepythondatetimemigration3.12Proprietary

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.python.migrate.ReplaceDatetimeUtcFromTimestamp

If the recipe isn’t available locally, install it with:

mod config recipes pip install openrewrite-migrate-python