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.
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.
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:
python -X warn_default_encoding -W error::EncodingWarning -m pytestFix 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.
| Removed in 3.15 | Use 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_parse | The re module |
| CGIHTTPRequestHandler and --cgi | A real web framework or WSGI server |
| types.CodeType.co_lnotab | co_lines() (PEP 626) |
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:
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 inferreddestis nowfoo, notf. Pass an explicitdestto keep the old name. - All
sqlite3.connect()parameters except database are now keyword-only. base64.urlsafe_b64decode()no longer requires padding unless you passpadded=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.
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:
- Run the suite on your current Python with
-W error::DeprecationWarningto expose APIs that are about to disappear. - Add Python 3.15.2 or later to the matrix as an allowed failure.
- Run once more with
-X warn_default_encodingand fix each file open. - Rebuild dependencies and check that compiled wheels exist for 3.15.
- 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.
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.