Offline

Lazy imports and the art of interpreter procrastination

Track:
Python Core, Internals, Extensions
Type:
Talk
Level:
intermediate
Duration:
30 minutes
View in the schedule

Abstract

From CLI developers to maintainers of large applications, many Python developers have been bitten by the high overhead of eagerly loading imports. Long start-up times can make it prohibitively costly to run simple commands like --help, and the memory overhead from loading every imported module eagerly can trigger Out-Of-Memory errors in production.

After the most discussed PEP thread in the history of discuss.python.org, with hundreds of messages and fierce debate, Python 3.15 finally brings Explicit Lazy Imports to the language. With a simple new keyword, you can now defer module loading until the moment you actually need it. This is one of the most requested performance features in Python's history, and finally it's here.

This presentation will take you through how we got here and where we're going. We'll look at why existing workarounds never quite worked, and how an earlier proposal (PEP 690) tried to make all imports lazy by default but was rejected. Then PEP 810 emerged with a different approach: explicit, opt-in syntax that the community accepted.

The heart of this talk is discovering how lazy imports actually work inside the interpreter. We'll trace through the bytecode, see how proxy objects stand in for unloaded modules, and watch the moment when your code first touches a lazy import and the real module snaps into place. You'll also learn about the future tooling that we are baking that will help you adopt this safely in your own projects.

Whether you're a beginner curious about Python's future, someone looking to speed up your CLI tools, or you just want to understand what's happening under the hood, this talk will give you everything you need to start using lazy imports with confidence.