Languages

How to Upgrade to Python 3.15: UTF-8 Default, Removed APIs and a Test Checklist

Python 3.15 changes the default file encoding and removes a batch of old APIs. Here is what breaks first and how to test for it in CI.

Tyler Brennan

Runtime & Language Tooling Writer

Published 7 min read
Woman coding on a laptop with a Python book nearby
On this page 6 sections

To upgrade to Python 3.15, first run your tests with -X warn_default_encoding, because UTF-8 is now the default for any open() call without an encoding argument. Then search for removed APIs, rerun your suite on 3.15.2 or later, and adopt lazy imports and frozendict in a separate change.

This guide is for teams that run Python services, scripts and libraries and want to upgrade without surprises. It covers the first failures you are likely to see, the commands that find them, and a test plan for CI. The official What's New page says Python 3.15 was released on October 9, 2026.

Backtrace tests developer tools and language releases against real projects. Our approach to a release like this is to read the removals first, because a new feature never breaks your build and a removed function does.

Which Python 3.15 change breaks code first?

The UTF-8 default is the most likely first failure. Python 3.15 uses UTF-8 for file I/O when no encoding is given, independent of the system's environment. Code that relied on a Windows code page or a legacy locale may now read or write different bytes.

The behavior only applies when you omit the encoding argument. The release notes advise passing one explicitly for compatibility across versions. They also state that encoding='locale' keeps the old behavior and has worked since Python 3.10.

Abstract display of floating letters and symbols, representing text encoding

Cross-platform teams feel this change the most. A script that wrote in a Windows code page on one runner and in UTF-8 on a Linux runner now behaves the same everywhere. The risk sits in old files on disk. A file written in a legacy encoding will now fail with a UnicodeDecodeError or, worse, decode into the wrong characters without any error.

You can find affected code with the opt-in warning. The io module documentation explains that the -X warn_default_encoding option, or the PYTHONWARNDEFAULTENCODING variable, emits an EncodingWarning whenever the default is used. Turn those warnings into errors in a test run:

text
python -X warn_default_encoding -W error::EncodingWarning -m pytest

Fix each hit by adding encoding="utf-8", or encoding="locale" when the file really is in the machine's native encoding. Reading config files and CSV exports is where this matters most. If you need a short-term escape hatch, set PYTHONUTF8=0 or pass -X utf8=0 to disable UTF-8 mode, then plan the real fix.

Which removed APIs should you search for before upgrading?

Search for the functions the release notes list as removed. Python 3.15 deletes several APIs that were deprecated in 3.13 and earlier. A missing function fails loudly at import or call time, so a text search before the upgrade saves an afternoon of tracebacks.

Which removed APIs should you search for before upgrading?
Removed in 3.15Use instead
glob.glob0(), glob.glob1()glob.glob() with root_dir
Loader.load_module()exec_module()
zipimporter.load_module()zipimporter.exec_module()
PurePath.is_reserved()os.path.isreserved()
platform.java_ver()No replacement listed
sre_compile, sre_constants, sre_parseThe re module
CGIHTTPRequestHandler and --cgiA real web framework or WSGI server
types.CodeType.co_lnotabco_lines() (PEP 626)
Lines of code on a computer screen, the kind of source files you search for removed APIs

Your own code is only half the picture. Libraries you depend on may call a removed function inside their own modules, and those failures show up in their stack frames, not yours. Check the release notes of your ten most important dependencies for a Python 3.15 statement, and run pip check after installing into a fresh environment.

Run one search across your repositories to catch most of them:

text
grep -rnE "load_module|glob0|glob1|is_reserved|java_ver|sre_(compile|constants|parse)|co_lnotab|CGIHTTPRequestHandler" --include="*.py" .

The typing module has removals too. The keyword-argument form NamedTuple("Point", x=int, y=int) no longer works, so use the class syntax. A zero-field TypedDict("TD") call also fails. In addition, typing.no_type_check_decorator is gone.

Check your tooling as well as your application. A dev script or test fixture that still starts python -m http.server --cgi now fails, because the flag is gone. Replace it with a small WSGI app, or a static server if the CGI part was never needed.

Two behavior changes are easy to miss because they used to warn. The ast node constructors now raise TypeError when a required argument is missing. And datetime.strptime() raises ValueError when a format has %d with no year directive.

What else in the Python 3.15 porting notes can change behavior?

Several quiet changes can alter results without raising an error. The porting section lists them, and you should read it line by line. The most likely to bite are the argparse, sqlite3, base64 and unittest items.

  • With add_argument('-f', '-foo'), the inferred dest is now foo, not f. Pass an explicit dest to keep the old name.
  • All sqlite3.connect() parameters except database are now keyword-only.
  • base64.urlsafe_b64decode() no longer requires padding unless you pass padded=True.
  • assertWarns() no longer swallows warnings that do not match, so tests may start leaking warnings.

The remaining notes are narrower. mmap.resize() is removed on platforms without the underlying system call, and resource.RLIM_INFINITY is now always positive, so passing a negative value to setrlimit() is deprecated. An unclosed iterparse() iterator that opened a file now emits a resource warning. These are rare, but each one fails quietly, so scan for the names once.

The unittest change deserves a plan. Tests that passed because a stray warning was hidden may now print noise or fail under strict warning filters. Add a warning filter for known noise, or catch the warning with an extra assertWarns().

One more detail affects deployment. The 3.15.2 notes describe a regression introduced in 3.15.0, where threads doing first-time import package.submodule imports at the same time could deadlock or raise spurious import errors. The fix landed in 3.15.2. If your service imports lazily from threads, pin to 3.15.2 or later.

How do you test a Python 3.15 upgrade in CI?

Add 3.15 to the test matrix first, as an allowed failure, and promote it once it is green. This keeps the main branch shippable while you fix the failures. A staged rollout beats a single big-bang change, and the same idea runs through our guide on testing a Node.js major version upgrade before production.

Laptop on a desk showing code in an editor, used here for running tests before an upgrade

Follow these steps in order, and note each fix in the pull request description so reviewers can map every change back to a line in the release notes:

  1. Run the suite on your current Python with -W error::DeprecationWarning to expose APIs that are about to disappear.
  2. Add Python 3.15.2 or later to the matrix as an allowed failure.
  3. Run once more with -X warn_default_encoding and fix each file open.
  4. Rebuild dependencies and check that compiled wheels exist for 3.15.
  5. Make 3.15 a required job, then switch the production image.

Keep the rollback path boring. Tag the current production image before the change, and pin the new base image to a specific 3.15 patch release of 3.15.2 or later rather than a floating tag. A pinned version means a bad night never turns into a surprise interpreter bump.

Dependencies are the usual blocker. A package without a 3.15 wheel falls back to a source build, which needs compilers in your image. Check the lockfile before the cutover, not during it.

Language upgrades in other stacks follow the same shape. Our Go 1.27 upgrade checklist pairs each default change with a test, and the case for that discipline is made in our piece on the importance of testing in software delivery.

Should you adopt lazy imports and frozendict right away?

No. Treat the new features as a second project after the upgrade settles. Mixing a version bump with a feature rollout makes failures hard to trace. Land the upgrade, watch it for a week, then adopt features one pull request at a time.

Computer on a desk at night, where a developer reviews code changes one at a time

The lazy keyword defers a module load until its name is first used. It is allowed only at module scope, and a failed lazy import raises at first use instead of at import time. That timing change can move an error from startup into a request handler. The -X lazy_imports=all option makes every import lazy, so test it before using it in production.

For a measured rollout, sys.set_lazy_imports_filter() accepts a callable that decides which modules may load lazily. You can make only your own packages lazy and keep third-party imports eager. That limits the blast radius to code you control.

The new frozendict type is immutable and hashable when its contents are hashable. It is not a subclass of dict. Code that checks isinstance(value, dict) will not match one, which is the main trap when you start passing them around.

Other additions are worth a look once things are calm. The release adds a sentinel built-in, unpacking inside comprehensions, and a dedicated profiling package that includes a sampling profiler named Tachyon. None of them is required for the upgrade, and none should share a pull request with it.

At Backtrace, our editors keep a simple rule for new language features: adopt one only when it removes a workaround you already maintain. Faster startup is a good reason. Novelty is not.

Conclusion

A Python 3.15 upgrade is mostly a search-and-test job. Fix the encoding warnings first, because they hide in plain file opens. Then clear the removed APIs, read the porting notes, and let CI prove it.

Write the encoding decision into your contributing guide so new code follows it from day one. Ship the version bump on its own. Features such as lazy imports and frozendict can follow once the new interpreter has run cleanly in production for a while.

When was Python 3.15 released?
Python 3.15 was released on October 9, 2026, according to the official What's New document. The documentation now covers 3.15.2, which includes a fix for a threaded import regression that appeared in 3.15.0. For production use, choose 3.15.2 or later rather than the initial 3.15.0 release.
How do I find code affected by the Python 3.15 UTF-8 default?
Run your tests with the -X warn_default_encoding option or set PYTHONWARNDEFAULTENCODING, which emits an EncodingWarning whenever the default encoding is used. Add -W error::EncodingWarning to fail the run on each hit. Then pass an explicit encoding, such as utf-8 or locale, to every text file open.
Can I turn off UTF-8 mode in Python 3.15?
Yes. Set the PYTHONUTF8=0 environment variable or pass -X utf8=0 on the command line to restore the previous behavior. Treat that as a short-term escape hatch. The release notes recommend giving every open call an explicit encoding, which keeps code consistent across Python versions and operating systems.
Is frozendict a subclass of dict in Python 3.15?
No. The new frozendict built-in inherits directly from object, so an isinstance check against dict will not match it. It is immutable, keeps insertion order, and is hashable when all keys and values are hashable. Update any type checks before you start passing frozendict values through existing code.

Written by

Tyler Brennan

Runtime & Language Tooling Writer

11+ years experience

Tyler spent nine years as a full-stack engineer at a mid-sized e-commerce company, where he owned the Node.js services and the build pipeline behind them. He ran four major runtime upgrades there and still keeps the habit of reading changelogs for what gets removed before what gets added. At Backtrace he covers language releases, package managers and the local tooling that decides how fast a team moves. His rule is simple: an upgrade guide is only useful if it lists the failure you will see first and the command that finds it.

Credentials

  • B.S., Computer Science, University of Wisconsin-Madison
  • Former Senior Full-Stack Engineer, e-commerce platform (2014-2023)
  • OpenJS Foundation Node.js Application Developer certification