Zum Inhalt springen
Michael Blaess
IT-Consulting
Michael Blaess
DE

Python 3.15 is here. Is it worth upgrading?

7 min read PythonPython 3.15PerformanceProfiling

Python 3.15 was released on October 9, 2026. The list of changes is long, and much of it only concerns people who write extensions in C.

I picked a few points that really matter to me in day-to-day work. All examples in this post ran on Python 3.15.0 under Windows 11, and the output shown is the real output.

New features in Python go through so-called PEPs. That stands for Python Enhancement Proposal, a numbered change request. If you want to know more about a point, you will find the full reasoning under that number.

Lazy imports: load only when needed

Normally an import at the top of a file loads the module right away. Python finds the file, reads it, compiles it and runs it. In an application with many dependencies this happens on every start, even if the call is only supposed to print --help.

PEP 810 adds the new keyword lazy for this:

import sys

lazy import json
lazy from pathlib import Path

print("json loaded:", "json" in sys.modules)
print(json.dumps({"version": "3.15"}))
print("json loaded:", "json" in sys.modules)
print("pathlib loaded:", "pathlib" in sys.modules)
json loaded: False
{"version": "3.15"}
json loaded: True
pathlib loaded: False

json is only loaded when it is used for the first time. pathlib is never needed in this run and therefore never loaded.

How much this gains depends on how much an application imports without using it. To get an impression I built a script with ten standard library modules that uses none of them:

import argparse, asyncio, decimal, email.message, http.client
import json, sqlite3, xml.etree.ElementTree, zipfile, urllib.request

print("ok")

On my machine the start takes 111 ms, measured as the median of 15 runs. With the environment variable PYTHON_LAZY_IMPORTS=all, which defers every import, it is 16 ms. That is the best case, because the script uses nothing at all. A real application would probably land somewhere in between.

But watch out: An import error now only shows up at the point where the module is used for the first time. A typo in a module name is no longer noticed at startup, but only when the affected part of the program runs for the first time. In addition, lazy is only allowed at module level. Inside a function, a class or a try block Python reports a syntax error.

frozendict: an immutable dictionary

Lists have the tuple, sets have the frozenset. The dictionary had no immutable counterpart so far. PEP 814 adds it:

DEFAULTS = frozendict(timeout=30, retries=3)

DEFAULTS["timeout"] = 60
# TypeError: 'frozendict' object does not support item assignment

updated = DEFAULTS | {"timeout": 60}
print(updated)
# frozendict({'timeout': 60, 'retries': 3})

If you need a changed value, you build a new frozendict. The original stays as it was.

There is a second benefit. A frozendict can be used as a key, as long as its values can be too:

cache = {frozendict(host="example.com", port=443): "connected"}

print(cache[frozendict(port=443, host="example.com")])
# connected

The order of the entries does not matter for the comparison.

But watch out: A frozendict is not a subclass of dict. A check with isinstance(value, dict) returns False. If you need that, check against collections.abc.Mapping.

sentinel: “nothing passed” is not the same as None

A function with an optional parameter has to tell whether the caller passed nothing or explicitly passed None. Until now you built an empty object() for this. That works, but in error messages it looks like this: <object object at 0x000001F3A4B2C3D0>.

PEP 661 turns this into a type of its own:

MISSING = sentinel("MISSING")


def lookup(key: str, default: str | None | MISSING = MISSING) -> str | None:
    values = {"a": "apple"}
    if key in values:
        return values[key]
    if default is MISSING:
        raise KeyError(key)
    return default


print(repr(MISSING))          # MISSING
print(lookup("b", None))      # None
print(lookup("b", "pear"))    # pear
lookup("b")                   # KeyError: 'b'

The value has a readable name and may appear directly in the type annotation.

Unpacking in comprehensions

To flatten a list of lists, you used to write this code:

pages = [["/", "/blog/"], ["/contact/"], []]

urls = [url for group in pages for url in group]

I have to read the double loop in one line twice every time 😕 With PEP 798 it works with the star you know from function calls:

urls = [*group for group in pages]
# ['/', '/blog/', '/contact/']

configs = [{"timeout": 30}, {"retries": 3}, {"timeout": 60}]
merged = {**c for c in configs}
# {'timeout': 60, 'retries': 3}

With dictionaries the later entry wins, just like with {**a, **b}.

Error messages that know other languages

If you switch between several languages, sooner or later you type the method of the wrong one. Python 3.15 recognizes some of these cases and names the matching counterpart:

>>> [1, 2, 3].push(4)
AttributeError: 'list' object has no attribute 'push'. Did you mean '.append'?

>>> {}.put("a", 1)
AttributeError: 'dict' object has no attribute 'put'. Use d[k] = v.

>>> (1, 2).append(3)
AttributeError: 'tuple' object has no attribute 'append'. Did you mean to use a 'list' object?

According to the official notes, Python knows common method names from JavaScript, Java, Ruby and C# for this. As someone who writes a lot of C# at work, I am happy about that 🙂

UTF-8 as the default

This change mainly affects Windows. Until now open() without an encoding used the one of the operating system. On a German Windows that is cp1252, on Linux and macOS it is UTF-8. The same script therefore wrote different bytes depending on the machine.

Since PEP 686 UTF-8 applies everywhere:

import locale

print(locale.getencoding())
# cp1252

with open("test.txt", "w") as handle:
    print(handle.encoding)
    # utf-8
    handle.write("Grüße")

The operating system still reports cp1252, open() writes UTF-8 anyway.

But watch out: This also applies to reading. A file that an older Python wrote on Windows without an encoding is stored in cp1252 and could fail on the umlauts when read with 3.15. The safe solution is the same as before: always spell out the encoding in open(). Then the code behaves the same on every version.

Tachyon: a profiler that barely slows the running program

The previous profiler cProfile hooks into every single function call. That is precise, but it can slow the program down considerably.

Tachyon from PEP 799 works differently. At fixed intervals it looks from the outside at where the program currently is, and counts. This is called statistical sampling. The code does not have to be changed for it.

A small example that first computes and then waits for two seconds:

import time


def compute() -> int:
    return sum(i * i for i in range(3_000_000))


def wait() -> None:
    time.sleep(2)


compute()
wait()
python -m profiling.sampling run wait.py
Captured 2.121 samples in 2,12 seconds

   nsamples   sample%   tottime (s)   filename:lineno(function)
  2000/2000      96.2         2.000   wait.py:9(wait)
      57/80       2.7         0.057   wait.py:5(compute)

The output is shortened, and the number format comes from my German system. 96.2 % of the time is spent waiting.

That is the default, it measures elapsed time. With --mode cpu Tachyon only counts the time in which something is actually computed. wait then no longer appears in the output at all.

This distinction would have helped me once before. With my terminal music player retro-amp the waiting functions were at the top of the profile and looked like load. An application that mostly waits for input simply spends its time waiting.

Three more calls I have made a note of:

python -m profiling.sampling attach 1234
python -m profiling.sampling dump 1234
python -m profiling.sampling run --live script.py

attach connects to a program that is already running, using its process ID. dump shows once where each thread currently is, which helps with a program that hangs. --live shows the evaluation continuously in the terminal.

More color in the terminal

One small thing to finish. python --help is now colored, as is the output of several standard library tools. For your own scripts difflib is interesting: difflib.unified_diff() has a new parameter color=True and then colors the comparison the way you know it from git diff.

What is removed?

Every new version also removes things that were marked as deprecated for a long time. The following points come from the sections “Removed” and “Porting” of the official notes:

  • datetime.strptime() reports an error if the format contains a day but no year.
  • With sqlite3.connect() every parameter except the database has to be passed by name.
  • The modules sre_compile, sre_constants and sre_parse no longer exist.
  • pathlib.PurePath.is_reserved() is removed, the replacement is os.path.isreserved().
  • The short form NamedTuple("Point", x=int, y=int) is no longer supported.

If you come from 3.13, you skip a version and should add the list for 3.14. The main item there is asyncio.get_event_loop(), which now reports an error when no loop is running.

Should you upgrade now?

For trying it out: yes, right away. For applications that get shipped, I would wait a little longer.

The reason is not Python itself, but the packages around it. Packages with a compiled part need a separate build for every Python version, and not all of them publish it on day one. On October 9, 2026 the file lists on PyPI were checked for this:

  • PyYAML and pygame did not have a build for 3.15 yet.
  • pydantic-core, Pillow, cryptography and lxml already had one.
  • PySide6 can be installed, but according to the Qt development notes support for 3.15 is only planned from version 6.12.1.

Then there is Nuitka, which I use to compile my applications into standalone programs. The Nuitka 4.2 changelog calls support for 3.15 “experimental at best”. I will not build a program with it yet that is meant to run on someone else’s machine 😕

What I learned from it

Lazy imports and Tachyon are the two new features that definitely make the upgrade worthwhile for me. One shortens startup, the other shows where the time really goes.

For my projects I will proceed as follows over the next few weeks: The tests now also run on 3.15, so that a break is noticed early. Building and shipping continues on the previous version until the packages have caught up.

A new Python version is no reason to rush. It is a reason to look at your own test coverage. If you trust your tests, you can simply try the upgrade and will know where you stand afterwards.

Sources (checked on October 9, 2026): What’s new in Python 3.15 · What’s new in Python 3.14 · Announcement on discuss.python.org · Documentation for profiling.sampling · Nuitka changelog · Qt for Python Development Notes

Planning a similar project?

I support you from consulting and planning through implementation to quality assurance.

“We can only see a short distance ahead, but we can see plenty there that needs to be done.”

- Alan Turing