Supporting Python versions#

Like other programming languages, Python evolves with time. New features get added to the language, and others get deprecated. For more information, see Status of Python branches.

Version

PEP

Released

Security Support Ends

Status

3.12

PEP 693

02 Oct 2023

Oct 2028

Stable

3.11

PEP 664

03 Oct 2022

Oct 2027

Stable

3.10

PEP 619

04 Oct 2021

Oct 2026

Stable

3.9

PEP 596

05 Oct 2020

Oct 2025

Stable

Consider supporting stable Python versions.

Python versions labeled as stable receive only security fixes. Versions labeled as dev are still receiving bug fixes.

Expect stable versions to be the most commonly used Python versions. Some packages like numpy drop support for older versions of Python earlier than their end of life (EOL) as outlined in NEP 29.

You can still install an older version from PyPI using pip as your package manager. When pip is used, it downloads and installs the most recent version of the library that supports your version of Python. You can enforce a minimum-required Python version within setup.py with:

from setuptools import setup

[...]

setup(name="my_package_name", python_requires=">3.9", [...])

This helps pip to know which versions of your library support which versions of Python. You can also impose an upper limit if you’re sure you don’t support certain versions of Python. For example, if you only support Python 3.9 through 3.12, your command would look like this: python_requires='>=3.9, <3.12'.

Verifying support#

The best way to validate whether a Python library supports a version of Python is by Using continuous integration. An example GitHub workflow testing Python 3.9 through Python 3.12 on Windows and Linux would start with:

 1jobs:
 2  tests:
 3    name: "Tests"
 4    runs-on: ${{ matrix.os }}
 5    strategy:
 6      matrix:
 7        os: [windows-latest, ubuntu-latest]
 8        python-version: ['3.9', '3.10', '3.11', '3.12']
 9    steps:
10      - name: "Run tests using pytest"
11        run: ansys/actions/test-pytest@v4
12        with:
13          python-version: ${{ matrix.os }}

The workflow would then list the tests to run.