[go: up one dir, main page]

Open In App

Python 3.13 New Features

Last Updated : 20 May, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Nearly annually, Python releases a new version. The most recent version, Python 3.13, will be available on May 8, 2024, following Python 3.12 in that order. This version introduced many new features and improvements. This is a pre-release of the next Python version, which introduced some new features as well as improvements to the existing ones. In this article, we will see what has been changed in Python version 3.13.

1. A Better Interactive Interpreter

Python 3.13 introduces significant improvements to the interactive interpreter along with enhanced error messages. The new interactive interpreter now supports colorization, providing a more visually appealing experience. This color support extends to tracebacks and doctest output as well. Users have the option to disable colorization through the PYTHON_COLORS and NO_COLOR environment variables.

Additionally, Python 3.12 includes a basic JIT (Just-In-Time) compiler, as per PEP 744. Although currently disabled by default, this compiler shows promising performance improvements, with plans for further enhancements in subsequent releases.

2. Experimental Just-in-Time (JIT) Compilation

Python introduces an experimental just-in-time (JIT) compiler which, when enabled, can speed up certain Python programs. The JIT compiler works by translating specialized Tier 1 bytecode to a new internal Tier 2 intermediate representation (IR), which is optimized for translation to machine code. Several optimization passes are applied to the Tier 2 IR before it's interpreted or translated to machine code.

Configuration options (--enable-experimental-jit) allow users to control the JIT's behavior at build and runtime, including enabling or disabling the JIT and the Tier 2 interpreter.

Potential Benefits of JIT Compiler

  • Significant performance improvements for specific code sections that benefit from machine code execution.
  • Opens doors for future optimizations that weren't previously possible with bytecode interpretation.

3. Experimental Free-Threaded CPython

CPython now supports running with the Global Interpreter Lock (GIL) disabled, allowing for free-threaded execution when configured with --disable-gil. Free-threaded execution enables better utilization of available CPU cores by running threads in parallel, benefiting programs designed for threading.

C-API extension modules need to be specifically built for the free-threaded build, and extensions should indicate support for running with the GIL disabled using appropriate mechanisms.

Understanding the GIL

  • The Global Interpreter Lock (GIL) is a mechanism in CPython that ensures only one thread can execute Python bytecode at a time.
  • This guarantees data integrity in Python's single-threaded nature but limits the ability to leverage multiple CPU cores effectively for certain tasks

Potential Benefits of Free-Threaded CPython

For CPU-bound tasks that can be effectively divided among multiple threads, Free-Threaded CPython has the potential to significantly improve performance by utilizing multiple CPU cores. This could be particularly beneficial for scientific computing, data analysis, and other computationally intensive workloads.

4. Improved Error Reporting and Guidance

Error tracking in Python has been improved in the latest version. The interpreter now colorizes error messages when displaying tracebacks by default. In another feature, the error message suggests the correct keyword argument, if an incorrect keyword was passed to a function.

Sometimes when a script has the same name as a standard library module, Python now provides a detailed error message and suggests renaming the module for better understanding.

Python
>>> sys.version_info
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'sys' is not defined. Did you forget to import 'sys'?

5. Interactive Shell Makeover (New REPL)

Python 3.13 introduces a much-anticipated improvement for interactive development, a brand new REPL (Read-Eval-Print Loop). This interactive shell makeover aims to provide a more user-friendly and informative experience for Python programmers.

Features of New REPL

Python 3.13 brings a revamped REPL with several enhancements designed to improve the interactive development experience:

  • Colorful Enhancements (Linux/macOS): Output now has color by default, making code and error messages easier to read and understand. (Note: This feature is currently not available on Windows.)
  • Integrated Help (F1): Quickly access the pydoc help browser directly within the REPL by pressing F1. No more switching between windows or terminals to find documentation.
  • Command History Navigation (F2): Effortlessly browse through your command history using the F2 key. This allows you to revisit previous commands and experiment with variations quickly.
  • Block Paste Mode (F3): For working with larger code blocks, a dedicated paste mode is available with F3. This simplifies pasting code snippets into the REPL without worrying about line breaks or indentation issues.
  • Simplified Exit (exit/quit): You can now simply type exit or quit to leave the REPL, eliminating the need for function calls like exit().

Benefits of New REPL (Read-Eval-Print Loop)

These improvements in the new REPL aim to streamline the interactive development process. Features like color highlighting and integrated help make it easier to understand code behavior and identify issues. Easy command history navigation and block paste mode expedite experimentation and code refinement.

6. Incremental Garbage Collection

Python 3.12 introduces incremental garbage collection, which significantly reduces maximum pause times for larger heaps. This improvement is particularly beneficial for applications with large amounts of memory allocation and deallocation

Python
# Python 3.12
import gc
gc.isincremental()  # Returns True

This feature allows Python applications to run more smoothly, with reduced impact from garbage collection pauses, leading to better overall performance and responsiveness.

7. Improved Error Reporting and Guidance

Error tracking in Python has been improved in the latest version. The interpreter now colorizes error messages when displaying tracebacks by default. In another feature, the error message suggests the correct keyword argument, if an incorrect keyword was passed to a function.

Sometimes when a script has the same name as a standard library module, Python now provides a detailed error message and suggests renaming the module for better understanding.

8. Memory Optimization for Docstrings

Python 3.13 introduces a subtle but impactful change aimed at improving memory efficiency: Memory Optimization for Docstrings. This feature tackles a hidden source of memory usage and file size associated with docstrings in Python code. Limitations of Traditional docstrings in Python are as follows:

  • Traditionally, docstrings in Python included any leading indentation spaces.
  • While seemingly harmless, these extra spaces contributed to the overall size of the compiled bytecode files (.pyc files) and potentially increased memory usage when the code was executed.

Benefits of Memory Optimization for Docstrings

  • Memory Optimization for Docstrings addresses this inefficiency. It automatically removes any leading indentation from docstrings before the compilation process.
  • This ensures that only the actual docstring content is stored, leading to:
    • Reduced memory footprint for compiled bytecode files.
    • Potentially lower memory usage during program execution, especially for projects with extensive docstrings.

9. Enhance Performance in Modules

Python 3.12 introduces several optimizations to enhance performance in various modules and functions:

Improved Performance of textwrap.indent()

The textwrap.indent() function now performs approximately 30% faster for large input sizes than before. This enhancement improves the efficiency of text manipulation operations.

Improved Import Times for Standard Library

Several standard library modules have seen significant improvements in import times. For instance, the import time of the typing module has been reduced by around a third by removing dependencies on re and contextlib.

10. Removal of Deprecated Modules ("Dead Batteries")

Deprecated modules are functionalities in Python's standard library that are considered outdated, insecure, or no longer actively maintained. While they might still work in older Python versions, they are discouraged for use in new projects.

Why Remove Deprecated Modules?

  • Keeping deprecated modules around can lead to confusion for developers, especially beginners, who might unknowingly use outdated functionalities.
  • They can also introduce security vulnerabilities if not maintained properly.
  • Removing them encourages developers to adopt newer, more secure, and better-supported alternatives.

Benefits of Removing Deprecated Modules

  • Cleaner and More Secure Codebase: By removing outdated modules, the Python core developers ensure a cleaner and more secure standard library.
  • Encourages Modern Practices: It pushes developers to adopt newer, more secure, and better-maintained functionalities.

Major new features of the 3.13 series, compared to 3.12

FeaturePython 3.12Python 3.13
Interactive Shell (REPL)Basic functionalityImproved with color support, multi-line editing, block paste mode, and keyboard shortcuts (Linux/macOS only)
Error MessagesFunctionalMore informative and specific error messages
Just-in-Time (JIT) CompilationNot availableIntroduced (Experimental)
Free-Threaded CPythonNot availableIntroduced (Experimental)
Docstring OptimizationStandard behaviorLeading whitespace removed to reduce memory usage
Deprecated ModulesMarked for deprecationRemoved entirely

Whats Next:

Download and Install Python Latest Version

Python Tutorial

Conclusion

These enhancements across various modules contribute to a more robust, efficient, and feature-rich Python ecosystem, catering to diverse development requirements and scenarios. Whether it's improving debugging capabilities, enhancing filesystem operations, or refining database interactions, Python 3.13 offers a plethora of upgrades to empower developers in building robust and scalable applications.


Similar Reads

How to convert Categorical features to Numerical Features in Python?
It's difficult to create machine learning models that can't have features that have categorical values, such models cannot function. categorical variables have string-type values. thus we have to convert string values to numbers. This can be accomplished by creating new features based on the categories and setting values to them. In this article, w
2 min read
Awesome New Features in Python 3.8
Python is a widely-used general-purpose, high-level programming language. It was initially designed by Guido van Rossum in 1991 and developed by Python Software Foundation. It was mainly developed for emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code. Python is a programming language that let
6 min read
Advance Features of Python
Python is a high-level, interpreted programming language that has easy syntax. Python codes are compiled line-by-line which makes the debugging of errors much easier and efficient. Python works on almost all types of platforms such as Windows, Mac, Linux, Raspberry Pi, etc. Python supports modules and packages, which encourages program modularity a
7 min read
Get OSM Features Within a Distance of a Point Using Python OSMnx Feature Module
In this article, we will see how we can get open street map features within a distance of a point (latitude-longitude) using the OSMnx feature module in Python. Syntax of osmnx.features.features_from_point() FunctionThe function creates a GeoDataFrame of OSM features within some distance of a point N, S, E, and W. Below is the syntax: osmnx.feature
3 min read
Python Features
Python is a dynamic, high-level, free open source, and interpreted programming language. It supports object-oriented programming as well as procedural-oriented programming. In Python, we don't need to declare the type of variable because it is a dynamically typed language. For example, x = 10 Here, x can be anything such as String, int, etc. In thi
5 min read
Zip function in Python to change to a new character set
Given a 26 letter character set, which is equivalent to character set of English alphabet i.e. (abcd….xyz) and act as a relation. We are also given several sentences and we have to translate them with the help of given new character set. Examples: New character set : qwertyuiopasdfghjklzxcvbnm Input : "utta" Output : geek Input : "egrt" Output : co
2 min read
Python PIL | Image.new() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.new() method creates a new image with the given mode and size. Size is given as a (width, height)-tuple, in pixels. The color is given as a single value for single-band images, and a tuple for multi-band images (with one value for each
2 min read
rangev2 - A new version of Python range class
range() is a built-in function of Python. It is used when a user needs to perform an action for a specific number of times. The range() function is used to generate a sequence of numbers. But the sequence of numbers produced by range is generally either decreasing or increasing linearly which means it is either incremented and decremented by a part
2 min read
Open a new Window with a button in Python-Tkinter
Python provides a variety of GUI (Graphic User Interface) such as PyQt, Tkinter, Kivy and soon. Among them, tkinter is the most commonly used GUI module in Python since it is simple and easy to learn and implement as well. The word Tkinter comes from the tk interface. The tkinter module is available in Python standard library.Note: For more informa
3 min read
How to create a new thread in Python
Threads in python are an entity within a process that can be scheduled for execution. In simpler words, a thread is a computation process that is to be performed by a computer. It is a sequence of such instructions within a program that can be executed independently of other codes. In Python, there are two ways to create a new Thread. In this artic
2 min read
Using mkvirtualenv to create new Virtual Environment - Python
Virtual Environment are used If you already have a python version installed and you want to use a different version for a project without bothering the older ones. it is good practice to use a new virtual environment for different projects. There are multiple ways of creating that, today we will create one using mkvirtualenv command. virtualenvwrap
2 min read
Connect new point to the previous point on a image with a straight line in Opencv-Python
OpenCV-Python is a library of Python bindings designed to solve computer vision problems. Let's see how to Connect a new point to the previous point on an image with a straight line. Step 1: Draw points on image: On a image we can mark points using cv2.circle( ) method. This method is used to draw a circle on any image. Syntax: cv2.circle(image, ce
3 min read
What's new in Python 3.9?
A new version of Python is coming! Soon, we'll be using it in our Python projects. As of 20/07/2020 Python 3.9 is in beta version(3.9.0b4) and will release the full version of Python 3.9 pretty soon. Enough of introduction. Let's get started and learn about the new features. 1. Dictionary merge and update operators : Python 3.9 introduces merge(|)
3 min read
Python VLC Instance - Creating new Media Instance
In this article we will see how we can create a Media instance from the Instance class in the python vlc module. VLC media player is a free and open-source portable cross-platform media player software and streaming media server developed by the VideoLAN project. Instance act as a main object of the VLC library with the Instance object we can creat
2 min read
Inserting data into a new column of an already existing table in MySQL using Python
Prerequisite: Python: MySQL Create Table In this article, we are going to see how to Inserting data into a new column of an already existing table in MySQL using Python. Python allows the integration of a wide range of database servers with applications. A database interface is required to access a database from Python. MySQL Connector Python modul
2 min read
Adding a new NOT NULL column in MySQL using Python
Prerequisite: Python: MySQL Create Table In this article, we are going to see how to add a new NOT NULL column in MySQL using Python. Python allows the integration of a wide range of database servers with applications. A database interface is required to access a database from Python. MySQL Connector Python module is an API in python for communicat
2 min read
Adding new enum column to an existing MySQL table using Python
Prerequisite: Python: MySQL Create Table In this article, we are going to see how to add a new enum column to an existing MySQL table using Python. Python allows the integration of a wide range of database servers with applications. A database interface is required to access a database from Python. MySQL Connector-Python module is an API in python
1 min read
How to switch to new window in Selenium for Python?
Selenium is the most used Python tool for testing and automation for the web. But the problem occurs when it comes to a scenario where users need to switch between windows in chrome. Hence, selenium got that cover as well. Selenium uses these methods for this task- window_handles is used for working with different windows. It stores the window ids
3 min read
Python SQLite - Creating a New Database
In this article, we will discuss how to create a Database in SQLite using Python. Creating a Database You do not need any special permissions to create a database. The sqlite3 command used to create the database has the following basic syntax Syntax: $ sqlite3 <database_name_with_db_extension> The database name must always be unique in the RD
3 min read
Python Psycopg2 - Concatenate columns to new column
In this article, we are going to see how to concatenate multiple columns of a table in a PostgreSQL database into one column. To concatenate two or more columns into one, PostgreSQL provides us with the concat() function. Table for demonstration: In the below code, first, a connection is formed to the PostgreSQL database 'geeks' by using the connec
2 min read
Python – The new generation Language
INTRODUCTION: Python is a widely-used, high-level programming language known for its simplicity, readability, and versatility. It is often used in scientific computing, data analysis, artificial intelligence, and web development, among other fields. Python's popularity has been growing rapidly in recent years, making it one of the most in-demand pr
6 min read
How to Filter and save the data as new files in Excel with Python Pandas
Sometimes you will want to filter and save the data as new files in Excel with Python Pandas as it can help you in selective data analysis, data organization, data sharing, etc. In this tutorial, we will learn how to filter and save the data as new files in Excel with Python Pandas. This easy guide will tell you the techniques you need to perform t
3 min read
Create a New Text File in Python
Creating a new text file in Python is a fundamental operation for handling and manipulating data. In this article, we will explore three different methods to achieve this task with practical examples. Whether you're a beginner or an experienced developer, understanding these methods will provide you with the flexibility to work with text files in P
2 min read
How to append new data to existing XML using Python ElementTree
Extensible Markup Language (XML) is a widely used format for storing and transporting data. In Python, the ElementTree module provides a convenient way to work with XML data. When dealing with XML files, it is common to need to append new data to an existing XML document. This can be achieved efficiently using Python's ElementTree module. What is P
4 min read
Python 3.12 - What's New and How to Download?
Python releases a new version almost every year. The latest version, that is, Python 3.12 was released on 2 October, 2023. This version introduced many new features and improvements. In this article, we will see some of the newly added features to Python 3.12. Table of Content Download and Install PythonImproved Error Messages in PythonMore Flexibi
9 min read
Comparing Old-Style and New-Style Classes in Python
In Python, the difference between old-style and new-style classes is based on the inheritance from the built-in object class. This distinction was introduced in Python 2.x and was fully adopted in Python 3.x, where all classes are new-style classes. In this article, we will see the difference between the old-style and new-style classes in Python. P
4 min read
Replace Commas with New Lines in a Text File Using Python
Replacing a comma with a new line in a text file consists of traversing through the file's content and substituting each comma with a newline character. In this article, we will explore three different approaches to replacing a comma with a new line in a text file. Replace Comma With a New Line in a Text FileBelow are the possible approaches to rep
2 min read
How to Add New Line in Dictionary in Python
When working with dictionaries, you might find yourself in a situation where you need to add a new key-value pair. This process is straightforward, but understanding the nuances can be very helpful. In this article, we will explore how to add new lines (key-value pairs) to dictionaries in Python with practical examples. Understanding Python Diction
3 min read
Python | Add new keys to a dictionary
Before learning how to add items to a dictionary, let's understand in brief what a dictionary is. A Dictionary in Python is an unordered collection of data values, used to store data values like a map, unlike other data types that hold only a single value as an element, a Dictionary holds a key: value pair. Key-value is provided in the dictionary t
8 min read
Git Features
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git relies on the basis of distributed development of software where more than one developer may have access to the source code of a specific application and can modify changes to it which may b
9 min read
Practice Tags :
three90RightbarBannerImg