Python

Python 3.13, released on October 7, 2024, significantly improves the language, its implementation, and the standard library. This version introduces features that could reshape how developers use Python, particularly in multi-threaded and performance-critical applications.

As someone who's been involved with Python core development, I can't help but reflect on how far we've come. Now, I'm excited to share with you the latest developments in Python 3.13.

Free-Threaded CPython: A New Era of Parallelism

The headline feature of Python 3.13 is the experimental support for running CPython without the Global Interpreter Lock (GIL). This change allows Python programs to fully utilize multi-core processors, potentially leading to substantial performance improvements for multi-threaded applications.

Eager to dive into Python's free-threaded future? You'll need a special build, typically named python3.13t or python3.13t.exe. The easiest route is to grab pre-built binaries marked as "free-threaded" from the official Windows and macOS installers. Feeling adventurous? (Let's be honest, who isn't when it comes to cutting-edge Python features?) Roll up your sleeves and build CPython from source using the --disable-gil option.

Free-threaded builds also have a safety net: you can still enable the GIL at runtime using the PYTHON_GIL environment variable or the -X gil=1 command-line option. You'll be at the forefront of Python's multi-threaded revolution, whichever path you choose!

It's worth noting that not all existing Python code will automatically benefit from this change, but if you've been architecting your Python code to leverage threading, you're likely to see the most significant gains.

The journey to this point wasn't straightforward. It involved years of work, countless discussions, and numerous iterations. But that's the beauty of Python's development process - it's driven by a community that's passionate about improving the language for everyone.

Just-In-Time Compilation: Speeding Up Python

Another major addition is an experimental Just-In-Time (JIT) compiler. When enabled, this feature can speed up Python programs by compiling frequently executed code to machine code at runtime.

The JIT compiler uses a technique called "copy-and-patch" and introduces a new intermediate representation (IR) for Python bytecode. While the performance improvements are modest for now, the Python development team expects to enhance this feature in future releases.

This addition is a testament to the dedication of the developers and contributors who've made it possible, representing countless hours of complex work.

An Interactive REPL

Python 3.13 introduces a new interactive shell based on the PyPy project. This upgrade brings several user-friendly features to the Python REPL:

  • Multi-line editing with history preservation
  • Direct support for REPL-specific commands, e.g exit, quit
  • Color-coded prompts and tracebacks
  • Interactive help browsing
  • Improved history navigation

Function Keys in the REPL

  • F1 brings up the interactive help menu
  • F2 shows your session history
  • F3 sets paste mode

The up arrow key was also upgraded: it now fetches complete code blocks, making editing multi-line structures like functions or classes far less tedious.

These changes make the interactive Python experience more user-friendly and productive, especially for developers who frequently use the REPL for testing and exploration.

Improved Error Messages

Python continues its trend of providing more helpful error messages. In version 3.13, error messages are now color-coded by default when displayed in the terminal. The interpreter also provides more context when a script shares a name with a standard library module, helping developers quickly identify and resolve common import-related issues.

These improvements might seem small, but they can make a world of difference, especially for newcomers to the language. It's part of Python's ongoing commitment to being beginner-friendly while still powerful enough for advanced users.

A GIF demonstrating Python 3.13's improved error output in a macOS terminal. The terminal has a dark background with the characteristic red, yellow, and green window control buttons at the top. The animation begins with a command prompt showing '> py' with a blinking cursor, presumably followed by a demonstration of the new, enhanced error message formatting and output that was introduced in Python 3.13. This improvement is part of Python's ongoing efforts to make error messages more user-friendly and informative for developers.
A GIF showcasing Python 3.12's error output in a macOS terminal. The terminal has a dark background with red, yellow, and green window controls at the top left. When a coding error occurs, Python 3.12 displays the standard traceback in white text on the dark background, showing the error location and type, but without the enhanced readability features and detailed contextual hints that would later be introduced in Python 3.13. The demo starts with '> py' at the prompt with a blinking cursor, ready for input.

Removal of "Dead Batteries"

Python 3.13 completes the process of removing several outdated and unmaintained modules from the standard library, as outlined in PEP 594. This initiative, known as the removal of "dead batteries," aims to streamline the standard library and reduce maintenance burden.

The following modules have been removed:

  • Audio-related: aifc, audioop, chunk, sndhdr, sunau
  • Internet protocols: cgi, cgitb, nntplib, telnetlib
  • System-specific: crypt, nis, ossaudiodev, spwd
  • Others: imghdr, mailcap, msilib, pipes, xdrlib

While these modules are no longer part of the standard library, many of them are available as separate packages on PyPI. Developers who rely on these modules should consider alternative solutions or install the standalone packages.

This cleanup process, while sometimes controversial, is crucial for the long-term health of the language. It's a reminder that Python, like any living language, evolves over time.

iOS and Android: Officially Supported Platforms

Python 3.13 now officially supports iOS and Android as tier 3 platforms in a significant move for mobile development. This change opens up new possibilities for Python in mobile app development and could lead to increased adoption of Python in the mobile space.

As tier 3 platforms, iOS and Android have:

  • A buildbot for continuous integration
  • At least one core developer supporting them
  • Non-source builds
  • Failures that don't block releases

While this is an initial step, it indicates Python's growing importance in mobile development. As support for these platforms matures, we may see more Python-based tools and frameworks emerging for mobile app creation.

Standard Library Updates

Several updates to the standard library enhance Python's capabilities:

  • A new dbm.sqlite3 module is now the default dbm backend
  • The argparse module now supports deprecating command-line options
  • New functions in the os module for working with Linux's timer notification file descriptors
  • The random module now has a command-line interface

Random Module CLI

The random module's new command-line interface allows you to generate random choices, integers, or floats using options like -c/--choice, -i/--integer, and -f/--float, with default behaviors based on input type when no options are specified.

# choice
$ python -m random --choice apple banana cherry
banana

# randint
$ python -m random --integer 6
3

# random float, uses uniform()
$ python -m random --float 7.5
4.3846251908721634

These updates might not make headlines, but they're the result of countless hours of work by dedicated contributors. Each improvement, no matter how small, makes Python a little bit better for all of us.

Looking Ahead

While Python 3.13 brings exciting changes, it's important to note that some features, like the free-threaded mode and JIT compiler, are still experimental. Developers should approach these features with caution in production environments.

The Python development team has also updated its release schedule. Starting with version 3.13, new releases will have two years of full support followed by three years of security fixes, extending the overall support period to five years.

Python 3.13 sets the stage for a more powerful, flexible, and developer-friendly Python ecosystem. As these experimental features mature, we can expect Python to become an even more compelling choice for a wide range of applications, from web development to scientific computing and beyond.

As a Core Developer, I'm excited to see where these changes will take us. But more than that, I'm grateful to be part of a community that continues to push the boundaries of what's possible with Python. Whether you're a seasoned developer or just starting out, there's never been a better time to be part of the Python community.

Related Posts

August 18, 2024 • Frank Valcarcel

What makes Enterprise Software Development Different?

Enterprise software powers large organizations, handling complex tasks across departments. From robust security to scalability, these solutions face unique challenges. Explore what makes software “enterprise-ready” and how to choose the right development approach for your business.

Image for 'This Week I Learned' blog post featuring tips on managing Git branches including renaming and syncing with remote changes.
October 8, 2019 • Frank Valcarcel

TWIL 2019-10-04

Join us for ‘TWIL,’ where Emily shares innovative Git tips for managing branches with rewritten history. Learn to sync local branches with remote changes and rename them effectively.