Post

Thanks for sharing, this is definitely a cool idea and quite promising. I wonder what could be done to make lazy imports automatic, so the end user doesn't even have to make it explicit, and the import is only imported once actually used?

I am sorry Hugo, in your diff I don't see the "lazy" keyword mentioned in the PEP. Why? How does the magic operate, then?

I used the PYTHON_LAZY_IMPORTS env var to make it easy to compare two runs using hyperfine: $ hyperfine --warmup 10 --runs 20 --export-json out.json \ "./python.exe -m pypistats --help" \ "PYTHON_LAZY_IMPORTS=on ./python.exe -m pypistats --help" That then calculates the "faster than" summary.

In the past I had achieved HUGE boosts on my Django app from switching almost everything to inline imports. Startup time went from like 10s to 100ms. Didn't know about this PEP, it's gonna be fucking amazing

For context, I got a networkx kink which essentially drags down almost every single one of my projects. For that specific instance I had on top pandas, numpy, xgboost and probably one or two other monsters.