Python 3.15 adds lazy imports, a frozendict type and a profiler

A release aimed at startup time and everyday ergonomics

Python 3.15.0, the newest major version of the language, was released on 9 October 2026. The Python Software Foundation's release page counts 5,643 commits from 1,012 contributors since Python 3.14. Three additions stand out: imports that load only when first used, a built-in immutable dictionary, and a sampling profiler in the standard library.

What are lazy imports in Python 3.15?

Normally, an import statement loads and runs a module the moment Python reaches it. Because most code puts its imports at the top of the file, starting a program can set off a cascade of loading. PEP 810, which describes the feature, notes that for command-line tools "even running the command with --help can load dozens of unnecessary modules and take several seconds."

Python 3.15 adds a soft keyword, lazy, written in front of an ordinary import or from-import statement. A lazy import defers loading and running the module "until the first time the imported name is used." The PEP, whose seven authors include Pablo Galindo Salgado and Thomas Wouters, says this can cut startup time, memory use and unnecessary work, and that it benefits command-line tools, test suites and applications with large dependency graphs.

The feature is opt-in. Ordinary imports are unchanged, and the keyword is only allowed at module level, not inside functions, classes or try blocks. For lazy names, some behaviour shifts: an error in a missing module surfaces when the name is first used rather than at the import line, and any side effects of loading the module happen at that point too. Application developers can also turn it on more widely with a command-line option or environment variable; the PEP discourages library authors from doing so.

What is Python's new built-in immutable dictionary?

PEP 814, by Victor Stinner and Donghee Na, adds frozendict, a new built-in type: a dictionary that cannot be changed after it is created. It keeps insertion order and supports the standard mapping methods for reading and iteration, but it is not a subclass of dict.

The PEP lists why that matters. A frozendict whose values are hashable is itself hashable, "just like tuple objects," so it can be used as a dictionary key, stored in a set, or passed to functions cached with functools.lru_cache. It also avoids the problem of mutable default argument values. Item order does not affect equality or the hash.

A built-in sampling profiler

Python has long shipped two profilers, profile and cProfile, that trace every function call and return. PEP 799, by Pablo Galindo Salgado and László Kiss Kollár, says this tracing adds significant overhead, can disable some interpreter optimisations, and that cProfile only observes the main thread.

The new profiler, known as Tachyon, instead samples a running program at intervals. The PEP describes it as introducing "zero overhead profiling" and says it supports multiple threads, async functions, free-threaded builds and attaching to processes that are already running. The release page calls it a "High frequency statistical sampling profiler."

The PEP also tidies up the tools under one new package, profiling: profiling.tracing holds the old cProfile code, with cProfile kept as an alias, and profiling.sampling holds Tachyon. The pure-Python profile module is deprecated: importing it warns in 3.15, all uses warn in 3.16, and it is scheduled for removal in 3.17.

Also in this release

The release page lists several further changes, including:

One caution

The release page warns users of macOS 27.0 that IDLE and other tkinter applications may hang when a menu command opens a dialog. It attributes this to a macOS change believed to affect tkinter in all current Python versions, not only 3.15. Users who depend on such tools are advised to hold off on macOS 27.0 or test first.

Sources

Related stories

More from Debug Duck

All stories from Debug Duck