Mentatcurated
Artificial Intelligence high · independent

The import that waits

Python 3.15 lets you mark any import lazy, so a program no longer loads and runs libraries it might never touch.

The final release candidate for Python 3.15 landed on 1 September, and the feature carrying the release is a single word. Write "lazy import matplotlib" at the top of a file and none of that plotting library is loaded, and none of its start-up code runs, until the first moment your program mentions matplotlib by name.

Outside that one position, lazy stays an ordinary word, so code that already uses it as a variable name keeps working.

Starting a Python program means working through its imports in order, and each one runs the whole of that library's own set-up code before your first line executes. A command-line tool that can draw a chart therefore pays for the charting library every time somebody asks it to print its version number. The firms that felt this most sharply built private versions of the fix years ago: Meta ran lazy imports inside Instagram's servers, Hudson River Trading inside its own copy of Python, and both report cutting start-up time by more than half. Those are self-measured figures on unusually large codebases with unusually deep dependency trees, and a small script will notice nothing. The mechanism needs no benchmark to believe: work you never ask for is work you never do.

Python turned this idea down once. A 2022 proposal made every import lazy by default with no source changes at all, and the language's stewards rejected it because the machinery it needed, quietly replacing the dictionary that holds a module's names, would have foreclosed the interpreter work they wanted next, a just-in-time compiler among it. That compiler is in 3.15 and faster again this cycle. Refusing the free version four years ago is what left room for the version that costs one keyword per line.

What got accepted is unusually strict about where it may appear. The word works only at the top of a file: inside a function, a class body or a try block it is a compile error, and it never spreads, so marking one import lazy says nothing about the imports inside the module it names. The proposal's own measurements put the cost of carrying the machinery at half a percent or less when nothing is actually deferred. Version 3.15 arrives on 1 October, and the payoff after that belongs to library authors more than to users: the wait a person feels at start-up is mostly other people's imports, so it shortens only as maintainers walk their own files and decide, one line at a time, what can be put off.

Want to try it?

The release-candidate downloads sit at the top of the announcement thread; install it alongside your current Python and run your test suite against it, which is the entire point of a release candidate.

Get the tool at discuss.python.org →

The lenses

Novelty 3
Impact · breadth 4
Impact · depth 3
Actionable 4
Delight 3
Substance 5
Hype 3

The facts

Ships3.15.0 release candidate 2 out 1 September 2026; the final release is scheduled for 1 October
Costfree and open source; the keyword is opt-in, so nothing you have already written changes
Limitsallowed only at the top level of a file, never inside a function, class or try block; laziness does not spread to the module you imported
Reported gainsMeta about 70% off initialization time, Hudson River Trading 50-70% off start-up, PySide 10-20%, all measured by those companies on their own very large codebases

Concepts

Open discuss.python.org →

How this connects

Tap a node to open it

How this connects