So Python 3.15 will introduce a new, ?lazy? import mechanism <https://peps.python.org/pep-0810/>.
So far I have done one script where I moved an import into the
function where it was used, instead of doing it globally; this reduced
the script startup time from around 1.5 seconds down to about a
quarter second.
?Lazy? imports would avoid the need for such workarounds, while
keeping all imports together so they can be found more easily.
So Python 3.15 will introduce a new, ?lazy? import mechanism <https://peps.python.org/pep-0810/>.
So far I have done one script where I moved an import into the
function where it was used, instead of doing it globally; this reduced
the script startup time from around 1.5 seconds down to about a
quarter second.
?Lazy? imports would avoid the need for such workarounds, while
keeping all imports together so they can be found more easily.
Faster startup is nice, but lazy importing doesn't reduce total runtime
of the program, right?
?Lazy?
From the initial idea I got that now we have to have the word lazy
scattered all over the place for every module that needs to be
loaded in such a manner:
lazy import blah
lazy import whatever
lazy from thisorthat import meh
Wouldn't it have been better if they used, e.g. "with" as a starter?
Like so:
with lazy:
import blah
import whatever
from thisorthat import meh
Then it would have been much smoother to handle.
I don?t think it will be needed for a great many modules. In my case,
it was only ever an issue with matplotlib.
Lawrence D?Oliveiro <ldo@nz.invalid> writes:
I don?t think it will be needed for a great many modules. In my
case, it was only ever an issue with matplotlib.
I defer importing bs4 sometimes, depending on what I'm doing.
That same script imports bs4, as it happens. It still manages an
overall startup time of just a quarter second.
I don?t think it will be needed for a great many modules.
On Thu, 26 Mar 2026 01:40:15 -0000 (UTC), Lawrence D?Oliveiro wrote:
?Lazy?
[PEP] TL;DR
From the initial idea I got that now we have to have the word lazy
scattered all over the place for every module that needs to be loaded in
such a manner:
lazy import blah
lazy import whatever
lazy from thisorthat import meh
Wouldn't it have been better if they used, e.g. "with" as a starter? Like
so:
with lazy:
import blah
import whatever
from thisorthat import meh
Then it would have been much smoother to handle.
My 2› worth...
On Sun, 29 Mar 2026 22:35:37 -0000 (UTC), Lawrence D?Oliveiro wrote:
I don?t think it will be needed for a great many modules.
One cannot say with certainty that this is the case.
On 3/25/2026 9:40 PM, Lawrence D?Oliveiro wrote:
So Python 3.15 will introduce a new, ?lazy? import mechanism
<https://peps.python.org/pep-0810/>.
So far I have done one script where I moved an import into the
function where it was used, instead of doing it globally; this reduced
the script startup time from around 1.5 seconds down to about a
quarter second.
?Lazy? imports would avoid the need for such workarounds, while
keeping all imports together so they can be found more easily.
Faster startup is nice, but lazy importing doesn't reduce total runtime
of the program, right?
| Sysop: | Tetrazocine |
|---|---|
| Location: | Melbourne, VIC, Australia |
| Users: | 15 |
| Nodes: | 8 (0 / 8) |
| Uptime: | 17:01:39 |
| Calls: | 214 |
| Files: | 21,502 |
| Messages: | 83,201 |