↓ Skip to main content
  1. Posts/

Explicit Lazy Imports In Python 3.15

··161 words·1 min·

🐍 Python 3.15 introduces explicit lazy imports: prefix an import statement with lazy, and the module is not loaded until the program actually needs it.

This can speed up tools that offer different operations. For example, a help command could appear without loading heavy dependencies that are only needed to perform a particular task.

There is a trade-off: import errors may surface later, when the module or function is used. The author also explains a backwards-compatible option: __lazy_modules__ makes Python 3.15 defer selected imports, while earlier versions ignore it and load them normally.

💡 Explanation in a nutshell
#

It is like waiting to open a toolbox until you need a tool. The program may start sooner, but any problem inside the box is discovered when you finally open it.

More information at the link 👇

Also published on LinkedIn.

Juan Pedro Bretti Mandarano
Author
Juan Pedro Bretti Mandarano