Python versions#
Like other programming languages, Python evolves with time. New features get added to the language, and other features get deprecated. For more information, see Status of Python versions in the Python Developer’s Guide.
Version |
PEP |
Released |
Security support ends |
Status |
3.12 |
02 Oct 2023 |
Oct 2028 |
Stable |
|
3.11 |
03 Oct 2022 |
Oct 2027 |
Stable |
|
3.10 |
04 Oct 2021 |
Oct 2026 |
Stable |
|
3.9 |
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 the setup.py
file with
this code:
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'
.
Verify Python support#
The best way to validate whether a Python library supports a version of Python is by Continuous integration. An example GitHub workflow testing Python 3.9 through Python 3.12 on Windows and Linux would start like this:
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.