Python 3.15's Lazy Imports: Make Your CLI 3x Faster
Working to Make Python Lazy
Python 3.15 introduces lazy imports, a feature that defers module loading until first use, significantly speeding up CLI applications and large codebases. The author, Henry Schreiner, explains the concept, shows how to use the new `lazy` keyword or the backward-compatible `__lazy_modules__` list, and introduces `flake8-lazy`, a tool he developed to automate adding lazy declarations. Real-world results show 2-4x speedups for `--help` in projects like cibuildwheel and repo-review. The post also covers edge cases, tips, and the author's positive experience using AI to develop the tool.
100+ ms is noticeable, getting under that makes your app feel snappier.