Python is a flexible and popular programming language. Developers love it for its simplicity and readability. With each new version, Python adds features to better serve its users. The latest version, Python 3.13.0, was released on October 7, 2024. This version includes many new features and improvements. Let's look at the major updates in Python 3.13.0.
Enhanced interactive interpreter
The interactive interpreter has been updated to allow multi-line editing and color output. This makes it easier to use and visually appealing, inspired by the features of PyPy. These improvements help developers write and debug code more easily.
Example:
def greet(name):
return f"Hello, {name}!"
print(greet("World"))
Production:
Experimental free-threaded build mode
Python 3.13.0 introduces an experimental mode that disables global interpreter locking (GIL). This allows multiple threads to run at the same time. This feature is available in the Windows and macOS installers. Improves the performance of multi-threaded applications and makes better use of modern multi-core processors.
Example:
import threading
def print_numbers():
for i in range(5):
print(i)
threads = ()
for _ in range(5):
thread = threading.Thread(target=print_numbers)
threads.append(thread)
thread.start()
for thread in threads:
thread.join()
Production:
Preliminary just-in-time (JIT) compiler
This release includes an experimental JIT compiler that aims to speed up execution by compiling parts of the code as it runs.
Although still in the early stages, this feature could lead to significant performance improvements in future releases, helping Python better compete with languages like Java and C#.
Improved locals() function
The behavior of the locals() built-in function has been refined to provide well-defined semantics when modifying the returned assignment. This improvement ensures that debuggers can operate more consistently.
This change helps developers by ensuring predictable behavior when interacting with local variable assignments.
Example:
def example_function():
x = 10
y = 20
local_vars = locals()
local_vars('x') += 5 # Modify local variable
return x, y
print(example_function())
Production:
(10, 20)
New memory management features
Python 3.13.0 includes an updated version of the mimalloc memory allocator, which is now optional but enabled by default if the platform supports it. This allocator helps reduce memory usage, especially for applications that use long docstrings.
Efficient memory management contributes to better performance and lower memory consumption in applications.
Example:
def large_docstring_function():
"""This is a function with a large docstring that is intended to demonstrate
how leading indentation is stripped to save memory."""
pass
Updated dbm module
The dbm module now uses the dbm.sqlite3 backend by default when creating new database files, improving its functionality and reliability.
This change simplifies the use of the dbm module by taking advantage of the robust features of SQLite.
Example:
import dbm
with dbm.open('example.db', 'c') as db:
db('key') = 'value'
print(db('key')) # Output: value
Production:
b 'value'
Changes to macOS support
The minimum supported version of macOS has been updated from 10.9 to 10.13 (High Sierra), which means older versions of macOS will no longer be supported.
This change allows developers to focus on modern macOS features and optimizations, ensuring compatibility with current systems.
Level 2 and 3 platform support
Python 3.13.0 has updated the WebAssembly System Interface (WASI) to level 2 support, while Emscripten is no longer officially supported. Additionally, iOS and Android are now classified as Level 3 supported platforms.
This categorization helps developers understand the level of support and stability they can expect when using Python on various platforms.
Writing improvements
New features of the typing module include support for default types in type parameters, a new type limitation annotation (typing.TypeIs), and an annotation to mark deprecations in the type system.
These enhancements improve type hinting capabilities, making Python more robust for type checking and improving code clarity.
Example:
from typing import TypeVar, List
T = TypeVar('T', bound=int)
def sum_numbers(numbers: List(T)) -> T:
return sum(numbers)
print(sum_numbers((1, 2, 3)))
Production:
6
Depreciations and eliminations
Python 3.13.0 sees the removal of many deprecated modules as described in PEP 594, which was intended to optimize the standard library. Modules such as aifc, cgi and telnetlib have been removed.
This cleanup reduces the overhead of the standard library and encourages developers to use more modern and efficient alternatives.
How to update your Colab for Python 3.13.0?
- Check your current Python version: To see which version of Python you are currently using, run the following command:
!python --version
- Install Python 3.13– Update your package list and install Python 3.13 with these commands:
!sudo apt-get update -y
!sudo apt-get install python3.13
- Update alternatives to target new version of Python: Configure the fallback system to point to the new version of Python:
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.13 2
- Check Python version again: Check if the update was successful by running:
!python --version
You can see my collaboration notebook. here.
Key Comparisons: Python 3.12.0 vs Python 3.13.0
Feature | Python 3.12.0 | Python 3.13.0 |
Interactive interpreter | Standard interpreter | Enhanced with multiline editing and color support |
Management Gil | GIL standard | Experimental non-threaded build mode |
Performance | 5% overall improvement with various optimizations | Introducing a preliminary JIT to increase performance |
Memory management | Standard memory management | Optional Mimalloc included, reducing memory usage |
Bug report | Improved error messages | Additional improvements to exception tracking |
dbm module | Standard dbm functionality | The default is to use the dbm.sqlite3 backend |
macOS support | Compatible with macOS 10.9 and later | Minimum support updated to macOS 10.13 |
Platform support | Standard platform support | WASI is Level 2; iOS and Android are level 3 |
Typing | New syntax for type annotations | New default value types, restricted annotations, and deprecations |
Conclusion
Python 3.13.0 is based on Python 3.12.0. It brings many improvements and new features that make it easier to use, perform better, and improve the developer experience. Key updates include a better interactive interpreter, new threading options, and early JIT compilation. These changes show that Python intends to remain useful as programming evolves.