Releasecore
Python 3.13
Python 3.13 came out on 2024-10-07. It adds a new interactive shell, an experimental free-threaded build, an experimental JIT and defined locals() semantics, and it removes 19 old modules.
- Language
- Python
- Version
- 3.13
- Released
- 2024-10-07
- End of life
- 2029-10
What is new
Python 3.13.0 was released on 2024-10-07.1 Its largest changes are a new interactive shell, an experimental build without the global interpreter lock, and an experimental just-in-time compiler. The examples on this page ran on CPython 3.13.18, 3.14.10 and 3.15.2. Most of them fail on 3.12, because they use syntax or functions that 3.12 does not have.
A new interactive shell
The default interactive shell is new, based on code from the PyPy project. It supports multiline editing with history, the commands help, exit and quit without brackets, colour prompts and tracebacks, help browsing with F1, history browsing with F2 and a paste mode with F3. The variable PYTHON_BASIC_REPL selects the old shell.9 See interactive mode.
Defined semantics for locals() (PEP 667)
In a function, a generator, a coroutine or a comprehension, each call of locals() now returns an independent snapshot of the local variables. Before 3.13, CPython returned the same dictionary each time and updated it at times that were not specified. frame.f_locals in these scopes is now a write-through proxy, so a debugger can change a local variable reliably.4
import sys
def snapshot():
x = 1
first = locals()
x = 2
second = locals()
print(first["x"], second["x"], first is second)
def write_through():
y = 1
sys._getframe().f_locals["y"] = 5
print(y, type(sys._getframe().f_locals).__name__)
snapshot()
write_through()
1 2 False
5 FrameLocalsProxy
On 3.12 and older, the two calls return one shared dictionary, which the second call updates:
def snapshot():
x = 1
first = locals()
x = 2
second = locals()
print(first["x"], second["x"], first is second)
snapshot()
2 2 True
The change also affects exec() and eval() in a function when they have no explicit namespace. Their changes to local variables are never visible to a later locals() call. Pass a dictionary as the namespace to read the results.15 See eval and exec and code and frame objects.
Free-threaded build (PEP 703)
CPython can be built with --disable-gil, which removes the global interpreter lock, so threads run Python code in parallel on several cores.5 In 3.13 this build is experimental and is not the default. It is a separate executable, usually python3.13t, and the official Windows and macOS installers can install it.11 The function sys._is_gil_enabled() tells whether the GIL is on in the running process. A C extension that does not declare support for free threading turns the GIL back on when it is imported.11 See free-threaded Python and the global interpreter lock.
An experimental JIT compiler (PEP 744)
A CPython built with --enable-experimental-jit includes a just-in-time compiler. Hot bytecode is translated to an internal representation of micro-operations, optimized, and then turned into machine code with the copy-and-patch technique. The JIT is off by default in the official builds, and the speed-up is modest.6 See the JIT compiler.
Better error messages
Tracebacks are in colour by default in a terminal. The variables PYTHON_COLORS, NO_COLOR and FORCE_COLOR control this. When a script has the same name as a module of the standard library and this causes an error, the message says so. For an unknown keyword argument, the message suggests the right one.10
import traceback
try:
"a b c".split(max_split=1)
except TypeError as error:
print(traceback.format_exception_only(error)[-1], end="")
TypeError: split() got an unexpected keyword argument 'max_split'. Did you mean 'maxsplit'?
On 3.12 and older the message has no suggestion:
import traceback
try:
"a b c".split(max_split=1)
except TypeError as error:
print(traceback.format_exception_only(error)[-1], end="")
TypeError: 'max_split' is an invalid keyword argument for split()
Typing
- PEP 696: a type parameter can have a default, as in
class Box[T = int]. This works forTypeVar,ParamSpecandTypeVarTuple.7 - PEP 702: the decorator
warnings.deprecated()marks a function or a class as deprecated. Type checkers report its use, and a call emitsDeprecationWarningat run time.8 - PEP 705:
typing.ReadOnlymarks an item of aTypedDictas read-only for type checkers.1 - PEP 742:
typing.TypeIsnarrows a type in both branches of a test. It is an alternative totyping.TypeGuard.1
import warnings
from warnings import deprecated
class Box[T = int]:
pass
(param,) = Box.__type_params__
print(param, param.has_default(), param.__default__)
@deprecated("use new_api() instead")
def old_api():
return 42
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
print(old_api())
print(caught[0].category.__name__, caught[0].message)
T True <class 'int'>
42
DeprecationWarning use new_api() instead
Smaller language and library changes
copy.replace(obj, **changes)makes a modified copy of a named tuple, a data class, adatetimeobject or any object with a__replace__()method.1 See named tuples and data classes.- The compiler strips the common leading white space from each line of a docstring. This makes
.pycfiles about 5 percent smaller, and it affects tools such asdoctest.12 - A class has the attribute
__static_attributes__, the names that its methods assign throughself.<name>, and__firstlineno__, the first line of the class definition.12 - The new exception
PythonFinalizationError, a subclass ofRuntimeError, signals that an operation is blocked while the interpreter shuts down.12 - The new module
dbm.sqlite3is the default backend ofdbm.1 ssl.create_default_context()sets the flagsVERIFY_X509_PARTIAL_CHAINandVERIFY_X509_STRICT.1
import copy
from collections import namedtuple
from dataclasses import dataclass
from datetime import date
Point = namedtuple("Point", "x y")
@dataclass(frozen=True)
class User:
name: str
admin: bool = False
print(copy.replace(Point(1, 2), y=5))
print(copy.replace(User("ann"), admin=True))
print(copy.replace(date(2024, 10, 7), year=2025))
class Vector:
"""
A point in the plane.
It has two coordinates.
"""
def __init__(self, x, y):
self.x = x
self.y = y
print(repr(Vector.__doc__))
print(Vector.__static_attributes__)
Point(x=1, y=5)
User(name='ann', admin=True)
2025-10-07
'\nA point in the plane.\n\n It has two coordinates.\n'
('x', 'y')
Platforms and support policy
- PEP 730 and PEP 738: iOS and Android are officially supported platforms, at tier 3.
wasm32-wasiis tier 2, andwasm32-emscriptenis no longer supported.1 - PEP 602 was changed so that a feature release has two years of bugfix support, followed by three years of security fixes. 3.13 is the first release with this policy. 3.9 to 3.12 have one and a half years of bugfix support and three and a half years of security fixes.1
Removed and deprecated
Removed in 3.13
Most items below were deprecated in an earlier release.13
- PEP 594: the 19 "dead batteries"
aifc,audioop,cgi,cgitb,chunk,crypt,imghdr,mailcap,msilib,nis,nntplib,ossaudiodev,pipes,sndhdr,spwd,sunau,telnetlib,uuandxdrlib. They were deprecated in 3.11. Most have a copy on PyPI with the prefixstandard-, and the docs name other replacements, such assubprocessforpipesandbase64foruu. - The
2to3program and the modulelib2to3. tkinter.tix.locale.resetlocale(). Uselocale.setlocale(locale.LC_ALL, "").- The namespaces
typing.ioandtyping.re. Import the names fromtyping. - The keyword-argument form of
TypedDict("TD", x=int). - Chained
classmethoddescriptors, which wrapped another descriptor such asproperty. pathlib.Pathobjects as context managers.re.template()and the flagre.TEMPLATE.unittest.findTestCases(),makeSuite()andgetTestCaseNames(). Use the methods ofTestLoader.- The
cafile,capathandcadefaultparameters ofurllib.request.urlopen(). Usecontext. configparser.LegacyInterpolationand the subscript access toimportlib.metadata.EntryPoint.
import importlib.util
dead = ["aifc", "audioop", "cgi", "cgitb", "chunk", "crypt", "imghdr", "mailcap", "msilib", "nis", "nntplib", "ossaudiodev", "pipes", "sndhdr", "spwd", "sunau", "telnetlib", "uu", "xdrlib", "lib2to3"]
print([name for name in dead if importlib.util.find_spec(name)])
[]
Deprecated in 3.13
The version in brackets is the planned removal.14
- In
http.server:CGIHTTPRequestHandlerand the--cgioption (3.15). pathlib.PurePath.is_reserved()(3.15). Useos.path.isreserved().platform.java_ver()(3.15).ctypes.SetPointerType()(3.15).glob.glob0()andglob.glob1(). Useglob.glob()withroot_dir.- In
wave:getmark(),setmark()andgetmarkers()(3.15). - In
typing: the keyword-argument form ofNamedTuple("Point", x=int)(3.15), aNamedTupleorTypedDictcall with no fields, andno_type_check_decorator()(3.15). typing.AnyStr(out of__all__in 3.16, removed in 3.18). Use the type parameter syntax.- In
sqlite3: more than one positional argument toconnect(), and keyword arguments for the callbacks ofcreate_function(),create_aggregate()and theset_*methods. They become keyword-only or positional-only in 3.15. - The format code
'u'ofarray(3.16). Use'w'. - The
maxsplit,countandflagsarguments ofre.split(),re.sub()andre.subn()as positional arguments. - The format specifier
'N'ofdecimal.Decimal(3.18). - Assignment to
__code__of a function with a code object of another kind, such as a generator.
Migration
Most code that runs on 3.12 without warnings runs on 3.13. These changes can break it.15
- Removed modules. An import of one of the 19 PEP 594 modules or of
lib2to3fails withModuleNotFoundError. Install thestandard-package from PyPI, or move to the replacement that the docs name.13 - locals(). Code that calls
locals()once and expects the dictionary to change later, or that reads the results ofexec()throughlocals(), now sees a snapshot. Pass an explicit namespace. - f_locals.
frame.f_localsin a function is a proxy, not a dictionary. Usedict(frame.f_locals)for a snapshot. - functools.partial. A
partialobject as a class attribute givesFutureWarning, because in a later release it binds as a method. Wrap it instaticmethod(). - pathlib.
Path.glob()andrglob()with a pattern that ends in**return files and directories, not only directories. Add a trailing slash to match only directories. - gzip and zipfile.
GzipFile.modeis the string'rb'or'wb', not an integer. The file thatZipFile.open()returns for reading has the mode'rb'. - getpass.
getpass.getuser()raisesOSErroron each failure. - Free threading. Packages with C extensions need pip 24.1 or newer to install in the free-threaded build.11
The bugfix release 3.13.4 adds the value os.path.ALLOW_MISSING for the strict parameter of os.path.realpath(), and it fixes path traversal problems in the extraction filters of tarfile (CVE-2025-4435 and others).16 The bugfix release 3.13.18 makes ssl reject certificate chains that contain one of a set of compromised eMudhra intermediate CA certificates.17 Upgrade from an older 3.13 release to the newest one.
Support dates
The release manager of 3.13 is Thomas Wouters.2 CPython releases have two phases of support.3
| Phase | From | To |
|---|---|---|
| Bugfix (binary installers, regular releases) | 2024-10-07 | 2026-09-30 (3.13.16) |
| Security (source-only releases, as needed) | October 2026 | October 2029 |
Development of 3.13 began on 2023-05-22. The first alpha came on 2023-10-13, beta 1 on 2024-05-08 and the first release candidate on 2024-08-01.2 PEP 719 marks 3.13.16 as the last regular bugfix release with binary installers. The security release 3.13.17 also had binary installers, as an exception.2 Security fixes come as source releases until about October 2029, five years after 3.13.0.3
The dates of the releases come from the changelog.18 For 3.13.16, PEP 719 gives a date one day later, 2026-10-01. 3.13.5 was a hotfix release.
| Release | Date |
|---|---|
| 3.13.0 | 2024-10-07 |
| 3.13.1 | 2024-12-03 |
| 3.13.2 | 2025-02-04 |
| 3.13.3 | 2025-04-08 |
| 3.13.4 | 2025-06-03 |
| 3.13.5 | 2025-06-11 |
| 3.13.6 | 2025-08-06 |
| 3.13.7 | 2025-08-14 |
| 3.13.8 | 2025-10-07 |
| 3.13.9 | 2025-10-14 |
| 3.13.10 | 2025-12-02 |
| 3.13.11 | 2025-12-05 |
| 3.13.12 | 2026-02-03 |
| 3.13.13 | 2026-04-07 |
| 3.13.14 | 2026-06-10 |
| 3.13.15 | 2026-08-05 |
| 3.13.16 | 2026-09-30 |
| 3.13.17 | 2026-10-21 |
| 3.13.18 | 2026-10-25 |
References
- What's New In Python 3.13, Summary, release highlights
- PEP 719: Python 3.13 Release Schedule, Release schedule; Bugfix releases; 3.13 Lifespan
- Status of Python versions, Python Developer's Guide, Supported versions
- PEP 667: Consistent views of namespaces, Specification
- PEP 703: Making the Global Interpreter Lock Optional in CPython, Specification
- PEP 744: JIT Compilation, Specification
- PEP 696: Type Defaults for Type Parameters, Specification
- PEP 702: Marking deprecations using the type system, Specification
- What's New In Python 3.13, A better interactive interpreter
- What's New In Python 3.13, Improved error messages
- What's New In Python 3.13, Free-threaded CPython
- What's New In Python 3.13, Other Language Changes
- What's New In Python 3.13, Removed Modules And APIs
- What's New In Python 3.13, New Deprecations
- What's New In Python 3.13, Porting to Python 3.13
- What's New In Python 3.13, Notable changes in 3.13.4
- What's New In Python 3.13, Notable changes in 3.13.18
- Changelog, Python 3.13 documentation, Python 3.13.18 final back to Python 3.13.0 final
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag QC3FN6 Edit this page History Report an error Markdown