Dhia Hmila
5 days ago

--

I completely agree. I don't think it's a good idea to use lazyimports everywhere, especially for web apps, which aren't the best candidates for this approach.

However, CLIs with multiple subcommands can benefit from lazy imports. Since each subcommand runs in a separate Python process, all modules must be reloaded each time a command is executed, even if they aren't needed everytime ( you do not necessarily need the same dependencies for `git commit` and `git push` for example). Lazy imports is one approach to help mitigate this overhead.

--

--

Dhia Hmila
Dhia Hmila

Written by Dhia Hmila

I’m a Senior Data Scientist and a python lover.

No responses yet