Use Fully Qualified datetime in Python

Whenever using the datetime module in Python, a highly recommended practice is to just import datetime at the top of the file, and use the fully-qualified module name in the code, as much as possible:

  • datetime.datetime
  • datetime.timedelta

If one does from datetime import datetime, it’s hard to figure out at-a-glance what datetime is referring to in the middle of a several-hundred-lines-of-code file.

For similar reasons, another common best practice in Python when using the typing module ( is to import is as import typing as T or import typing as t (e.g.;

blog comments powered by Disqus


02 November 2022


Make a Donation