Replace datetime.utcnow() with datetime.now(UTC)
Recipe ID
org.openrewrite.python.migrate.ReplaceDatetimeUtcNowArtifactopenrewrite-migrate-pythonThe datetime.utcnow() method is deprecated in Python 3.12. Replace it with datetime.now(UTC), importing UTC from datetime where the name is not already in scope. The result is timezone-aware where utcnow() 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.ReplaceDatetimeUtcNowIf the recipe isn’t available locally, install it with:
mod config recipes pip install openrewrite-migrate-python