Python 3.13, the latest stable release, brings a range of significant updates to the language, implementation, and standard library. A notable improvement is the interactive shell (REPL), now enhanced with features such as color support, multi-line editing, block paste mode, and keyboard shortcuts for Linux and macOS. Error messages have also been refined, becoming more informative and featuring default colored tracebacks for easier debugging.

Among the experimental features introduced in Python 3.13 are the Just-in-Time (JIT) compilation (PEP 744) and the free-threaded CPython mode (PEP 703), both marking a step forward in performance and parallelism. Other updates include clearer semantics for the locals() function's returned mapping and support for default values in type parameters.

The standard library has undergone cleanup, with deprecated APIs and modules removed, including legacy modules previously marked for deprecation in Python 3.11 (PEP 594). Additionally, Python 3.13 optimizes memory usage by removing leading whitespace in docstrings. These changes collectively enhance Python’s user-friendliness, precision, and performance.

1. A better interactive interpreter

This interpreter is known as the REPL because it uses a read-evaluate-print loop. The REPL receives your input, evaluates it, and outputs the result before looping back and repeating the process.

Python

Python now features a new default interactive shell, adapted from the PyPy project, offering several improvements for a more seamless REPL experience.

If users prefer the old shell, they can revert to it by setting the PYTHON_BASIC_REPL environment variable.

2. Improved Error Messages

In Python 3.13, tracebacks displayed in the terminal now include color by default, enhancing readability when runtime errors occur. This behavior can be customized using the new PYTHON_COLORS environment variable, as well as the standard NO_COLOR and FORCE_COLOR options. Additionally, error messages have been improved to not only highlight issues but also provide suggestions for fixing them.

Python

3. Free-Threaded CPython

Free-threaded execution enables optimal use of available processing power by allowing threads to run concurrently across CPU cores. Although not all software will automatically take advantage of this feature, programs designed with threading in mind are likely to perform better on multi-core systems. It's important to note that the free-threaded mode is still experimental, and ongoing improvements may lead to some bugs and a significant decrease in single-threaded performance. Free-threaded builds of CPython can optionally run with the Global Interpreter Lock (GIL) enabled at runtime by using the environment variable PYTHON_GIL or the command-line option -X gil=1.

To determine if the current interpreter supports free-threading, run

python -VV

and check if the output includes “experimental free-threading build.” Additionally, the new function

sys._is_gil_enabled()

can be used to verify whether the GIL is disabled in the running process.

4. Experimental JIT (Just-In-Time) compiler

A just-in-time (JIT) compiler serves as a middle ground by allowing the interpreter to compile certain code while a program is running, thereby enhancing its speed. In Python 3.13, a new experimental JIT compiler has been introduced. Being experimental means it is included in Python's source code but is not enabled by default.

To experiment with the JIT compiler, you must set up a specific version of Python 3.13 with JIT enabled, similar to the process for using free-threaded Python but with different build flags. When CPython is configured and built using the

--enable-experimental-jit

a JIT compiler is added that can potentially speed up certain Python programs. JIT compilation can significantly improve performance, particularly in scenarios where the same operation is executed repeatedly, allowing the JIT compiler enough time to analyze and optimize your code.

5. Improvements to standard library

There have been excellent additions made to the standard library, which are as follows:

6. Removal of packages

Deprecated modules are functionalities in Python’s standard library that are discouraged for use in new projects, even though they may still function in older versions of Python. These are considered outdated, insecure, or no longer actively maintained.