josiete.com

Imports

Python 3.15: import only when needed

Raised blue and yellow Python logo on a dark surface, with blurred blocks in the background

Importing a library can involve reading files, executing initialization code, and loading further dependencies. We pay that cost even when we only want to display a tool’s help message. Python 3.15 introduces Explicit Lazy Imports, defined in PEP 810 and covered in What’s New in Python 3.15: we can declare an import and defer loading until first use.