Get started¶
flake8-lazy helps keep import-time overhead low by detecting imports that can be
declared as lazy in __lazy_modules__. For this package itself,
flake8-lazy --help runs roughly twice as fast when using Python 3.15's new
lazy import system (following PEP 810).
Error messages will mention __lazy_modules__, but the lazy keyword is
supported too.
Installation¶
Usually you would include this in some sort of dependency-group in your project,
e.g. dev or lint. There's also a standalone runner. If you use uv or pipx,
you can run it from anywhere without installation:
Run through flake8¶
The plugin is auto-discovered by flake8 via entry points.
Run through pre-commit¶
flake8-lazy ships a pre-commit hook, so you can run
the standalone checker without installing it into your environment. Add it to
your .pre-commit-config.yaml:
By default the hook only reports diagnostics. To have it rewrite files in place,
pass --apply:
- repo: https://github.com/henryiii/flake8-lazy
rev: v0.8.1
hooks:
- id: flake8-lazy
args: [--apply=list]
Next steps¶
- Rule reference — all LZY error codes
- Examples — common patterns and diagnostics
- CLI mode — standalone runner and
--applyauto-fix - How it works — detection logic and lazy-capable imports
Acknowledgements¶
GitHub Copilot in VS Code was used to help develop this package. The Scientific Python Development Guide template was used as a starting point.