
When someone types tool --help, should Python load the machinery for exporting a report? Python 3.15, released on October 9, 2026, lets a module declare that a particular import can wait until the program uses it. For command-line tools with several independent commands, that changes which startup costs the shortest command has to pay. Python release announcement
Follow the import through one command
Imagine a small tool that can print its version or export rows as CSV. Its entry module exposes the export function shown below. A conventional module-level import initializes the CSV module when Python runs that import, even on a path that only prints the version. The new spelling lets the interpreter postpone that work. The dependency remains visible at the top of the file.
lazy import csv
def write_report(rows, destination):
writer = csv.writer(destination)
writer.writerows(rows)
Defining write_report leaves the import deferred. Calling the function and accessing csv.writer triggers resolution. If another part of the process has already initialized the module, the existing module cache affects what happens at that point. Choose candidates by tracing your own entry point. PEP 810
Look for dependencies that do work at import time
Some imports populate a registry or install a handler. An image exporter might register itself simply because its module was imported. Making that import lazy can leave the format missing from a menu, since building the menu never accesses the exporter. Search for registration calls and write a test that lists all formats in a fresh process before changing the import.
Errors move too. If a dependency is missing, the first export can fail after a successful startup. Exercise that path in packaging tests. The syntax belongs at module scope, and Python restricts its use in exception-handling blocks. A project that still supports Python 3.14 also needs to keep the new syntax out of files that the older interpreter must parse. Python import statement reference
Measure the two experiences separately
Run the installed command in a new process each time. Measure the help command, then an export with a small fixed input, on the same interpreter and machine. Alternate the old and new builds for several runs and compare the median for each command. Keep the first export in the results. A faster help screen and an unchanged full export can be a worthwhile outcome when help is frequent and export is occasional.
