flake8-datetime-import
flake8-datetime-import is an opinionated plugin which aims to reduce
confusing or inconsistent usage of Python's datetime module. It checks that
datetime and time are imported as modules and aliased like:
import datetime as dt
import time as tm
Installation
pip install flake8-datetime-import
flake8 codes
| Code | Description |
|---|---|
| DTI100 | from datetime import ... is not allowed. datetime must be imported as a module. |
| DTI101 | datetime imported without aliasing as dt. Expected import datetime as dt. |
| DTI200 | from time import ... is not allowed. time must be imported as a module. |
| DTI201 | time imported without aliasing as tm. Expected import time as tm. |
Rationale
datetime and time are confusing when encountered in code. Are they modules?
Are they classes or functions?
# Bad
import datetime
from datetime import datetime, time, timezone
import time
from time import time, timezone
Consistently importing and aliasing the datetime and time modules helps
prevent this ambiguity.
# Good
import datetime as dt
import time as tm
dt.datetime.now()
tm.time()
Importing and namespacing datetime prevents other naming collisions,
such as Django's django.utils.timezone:
import datetime as dt
from django.utils import timezone
dt.timezone.utc
timezone.now()
This plugin was inspired by:
- A talk by @brandon-rhodes at PyCon Canada in which he mentioned this importing strategy
- Code review fatigue
Other notable mentions of this importing strategy:
pre-commit
To use with pre-commit, add flake8-datetime-import as an additional
dependency to flake8.
# .pre-commit-config.yml
- repo: https://github.com/pycqa/flake8
rev: 7.3.0
hooks:
- id: flake8
additional_dependencies: [
flake8-datetime-import,
]
Metadata
Release files for flake8-datetime-import 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flake8_datetime_import-1.0.0.tar.gz | 33.9 kB | With provenance | Details for flake8_datetime_import-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flake8_datetime_import-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for flake8_datetime_import-1.0.0-py3-none-any.whl |
Total release size: 38.3 kB
Release files / flake8_datetime_import-1.0.0.tar.gz
| Download URL | flake8_datetime_import-1.0.0.tar.gz |
|---|---|
| Size | 33.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7aeca9d4829cf9c8725b1fbfd95255e6468f977b07124b6ec8c04c4b8fa7b04b
|
|
BLAKE2b-256 checksum How to use checksums |
af2fc00a4cb787b50622936446b9b64fd927ee0fb9e6c92686b4b1d355f0a67c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 29, 2026.
Transparency logRelease files / flake8_datetime_import-1.0.0-py3-none-any.whl
| Download URL | flake8_datetime_import-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2847ebfcc2567bde7e9b8fce9ed91e6bb2fbba571382a5efde949df69ad70483
|
|
BLAKE2b-256 checksum How to use checksums |
47bbd0fc0c8d76f173c7e63ca5928a23d0520aaa39affe0b1fc91084451f3ba1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 29, 2026.
Transparency logSecurity for flake8-datetime-import 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for flake8_datetime_import-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.