PEP 803 – “abi3t”: Stable ABI for Free-Threaded Builds
- Author:
- Petr Viktorin <encukou at gmail.com>
- Discussions-To:
- Discourse thread
- Status:
- Draft
- Type:
- Standards Track
- Requires:
- 703, 793, 697
- Created:
- 19-Aug-2025
- Python-Version:
- 3.15
- Post-History:
- 08-Sep-2025, 20-Nov-2025, 16-Feb-2026
Abstract
Add a new variant of the Stable ABI, called “Stable ABI for Free-Threaded
Python” (or abi3t for short), and a corresponding API limitations.
abi3t will be based on the existing Stable ABI (abi3), but make the
PyObject structure opaque.
This will require users to migrate to new API for common tasks like defining
modules and most classes.
At least initially, extensions built for abi3t will be compatible with
the existing Stable ABI (abi3).
Terminology
This PEP uses “GIL-enabled build” as an antonym to “free-threaded build”,
that is, an interpreter or extension built without Py_GIL_DISABLED.
Motivation
The Stable ABI is currently not available for free-threaded builds.
Extensions will fail to build for a both Limited API and
free-threaded Python (that is, when both Py_LIMITED_API and
Py_GIL_DISABLED preprocessor macros are defined).
Extensions built for GIL-enabled builds of CPython will fail to load
(or crash) on free-threaded builds.
In its acceptance post for PEP 779, the Steering Council stated that it “expects that Stable ABI for free-threading should be prepared and defined for Python 3.15”.
This PEP proposes the Stable ABI for free-threading.
Background
Python’s Stable ABI (abi3 for short), as defined in PEP 384 and
PEP 652, provides a way to compile extension modules that can be loaded
on multiple minor versions of the CPython interpreter.
Several projects use this to limit the number of
wheels (binary artefacts)
that need to be built and distributed for each release, and/or to make it
easier to test with pre-release versions of Python.
With free-threading builds (PEP 703) being on track to eventually become the default (PEP 779), we need a way to make a Stable ABI available to those builds.
To build against a Stable ABI, the extension must use a Limited API, that is, only a subset of the functions, structures, etc. that CPython exposes. Both the Limited API and the current Stable ABI are versioned, and building against Stable ABI 3.X requires using only Limited API 3.X, and yields an extension that is ABI-compatible with CPython 3.X and any later version (though bugs in CPython sometimes cause incompatibilities in practice).
The Limited API is not “stable”: newer versions may remove API that were a part of older versions.
This PEP proposes additional API limitations, as required to be compatible with both GIL-enabled and free-threaded builds of CPython.
Rationale
The design in this PEP uses several constraints:
- Separate ABI
- The new ABI (
abi3t) will conceptually be treated as separate from the existing Stable ABI (abi3).However, it will be possible to compile a single extension module that supports both free-threaded and GIL-enabled builds. This should involve no additional limitations, at least in the initial implementation, and so it will be preferred over building
abi3t-only extensions. - No backwards compatibility now
- The new stable ABI variant will not support CPython 3.14 and below.
Projects that need this support can build separate extensions specifically
for the 3.14 free-threaded interpreter, and for older stable ABI versions.
However, we won’t block the possibility of extending compatibility to CPython 3.14 and below, and we recommend that package installation tools prepare for such extensions. See a rejected idea for how this could work.
- API changes are OK
- The new Limited API variant may require extension authors to make significant changes to their code. Projects that cannot do this (yet) can continue using the existing Limited API, and compile separately for GIL-enabled builds and for specific versions of free-threaded builds.
Tag name
The tag abi3t is chosen to reflect the fact that this ABI is similar to
abi3, with minimal changes necessary to support free-threading (which
uses the letter t in existing, version-specific ABI tags like cp314t).
Specification
Stable ABI for free-threaded builds
Python will introduce a new stable ABI, called stable ABI for free-threading
builds, or abi3t for short.
As with the current Stable ABI (abi3), abi3t will be versioned
using major (3) and minor versions of Python interpreter.
Extensions built for abi3t 3.x will be compatible with
CPython 3.x and above.
To build a C/C++ extension for abi3t, the extension will need to only
use limited API for free-threaded builds.
Like the existing Limited API, this will be a subset of the general CPython
C API.
Initially, it will also be a subset of the Limited API.
We will strive to keep it as a subset, but will not guarantee this.
Since abi3t and abi3 will overlap, it will be possible for a single
compiled extension to support both at once, and thus be compatible with
CPython 3.15+ (both free-threaded and GIL-eanbled builds).
Initially, any extension compiled for abi3t will be compatible with
abi3 as well.
Choosing the target ABI
Users of the C API – or build tools acting on their behalf, configured by tool-specific UI – will select the target ABI using the following macros:
Py_LIMITED_API=<version>(existing): Compile forabi3of the given version.Py_TARGET_ABI3T=<version>(proposed here): Compile forabi3tof the given version.
These two macros are functionally very similar.
In hindsight, Py_TARGET_ABI3 (without the T) would be a more fitting
name for Py_LIMITED_API.
We keep the existing name for backwards compatibility.
For ease of use and implementation simplicity, respectively, Python.h will
set the configuration macros automatically in the following situations:
- If
Py_LIMITED_API=vandPy_GIL_DISABLEDis set, thenPy_TARGET_ABI3Twill be defined asvby default. (This allows choosingabi3tby defining the pre-existing macro and compiling with free-threaded CPython headers. Note that in CPython 3.14, this case results in a compile-time error.) - If
Py_TARGET_ABI3T=vis set, CPython may define or redefinePy_LIMITED_APIasv. (This means that CPython can continue to use thePy_LIMITED_APImacro internally to select which APIs are available.)
Opaque PyObject
abi3t will initially have a single diffenerce from abi3: the
PyObject structure and APIs that depend on it are not part of abi3t.
Specifically, when building for abi3t, the CPython headers will:
- make the following structures opaque (or in C terminology, incomplete
types):
PyObjectPyVarObjectPyModuleDef_BasePyModuleDef
- no longer include the following macros:
PyObject_HEAD_PyObject_EXTRA_INITPyObject_HEAD_INITPyObject_VAR_HEADPy_SET_TYPE()
In both the regular stable ABI (abit3 3.15+) and the new
abi3t, the following will be exported functions (exposed in the ABI)
rather than macros:
Implications
Making the PyObject, PyVarObject and PyModuleDef structures
opaque means:
- Their fields may not be directly accessed.
For example, instead of
o->ob_type, extensions must usePy_TYPE(o). This usage has been the preferred practice for some time. - Their size and alignment will not be available.
Expressions such as
sizeof(PyObject)will no longer work. - They cannot be embedded in other structures.
This mainly affects instance structs of extension-defined types,
which will need to be defined using API added in PEP 697 – that is,
using a
structwithoutPyObject(or other base class struct) at the beginning, withPyObject_GetTypeData()calls needed to access the memory. - Variables of these types cannot be created.
This mainly affects static
PyModuleDefvariables needed to define extension modules. Virtually all extensions will need to switch the new export hook added in PEP 793 (PyModExport_modulename()) to supportabi3t.
The following functions will become practically unusable in abi3t,
since an extension cannot create valid, statically allocated, input
for them.
They will, however, not be removed.
Runtime ABI checks
Users – or rather build/install tools acting on users’ behalf – will continue to be responsible for not putting incompatible extensions on Python’s import paths. This decision makes sense since tools typically have much richer metadata than what CPython can check. Typically, build tools and installers use PyPA packaging metadata and platform compatibility tags to communicate compatibility details, but other models are possible.
However, CPython will add a line of defense against outdated or misconfigured tools, or human mistakes, in the form of a new module slot containing basic ABI information. This information will be checked when a module is loaded, and incompatible extensions will be rejected. The specifics are left to the C API working group (see issue 72).
This slot will become mandatory with the new export hook added in PEP 793. (That PEP currently says “there are no required slots”; it will be updated.)
Check for non-free-threaded ABI in free-threading builds
Additionally, in free-threaded builds, PyModuleDef_Init() will detect
extensions using the non-free-threading Stable ABI, emit an informative
message when one is loaded, and raise an exception.
(Implementation note: A message will be printed before raising the exception,
because extensions that attempt to handle an exception using incompatible ABI
will likely crash and lose the exception’s message.)
This check for non-free-threading abi3 relies on internal bit patterns
and may be removed in future CPython versions,
if the internal object layout needs to change.
The abi3t wheel tag
Wheels that use a stable ABI compatible with free-threading CPython builds
should use a new ABI tag: abi3t.
Recommendations for installers
Package installers should treat this tag as completely separate from abi3.
They should allow abi3t-tagged wheels for free-threaded builds wherever
they currently allow abi3-tagged ones for (orherwise equal)
non-free-threaded builds.
Recommendations for build tools
Build tools should give users one or two additional options, in addition to
the existing CPython version-specific ABI (cp3nn) and
Stable ABI (abi3):
- Compile extensions compatible with both
abi3andabi3t, by either:- defining both
Py_LIMITED_API=vandPy_TARGET_ABI3T=v, or - defining
Py_LIMITED_API=vand:- defining
Py_GIL_DISABLED(on Windows) - building with free-threaded CPython headers (elsewhere)
- defining
Such extensions should be tagged with the compressed tag set
abi3.abi3t. - defining both
- Compile extensions compatible with only
abi3t, by defining onlyPy_TARGET_ABI3T=vand tagging the result withabi3t. This will initially offer no advantages over theabi3.abi3toption above, but there is a possibility that it will become useful in the future.
In the above, v stands for a the lowest Python version with which
the extension should be compatible, in Py_PACK_VERSION() format.
In the cases above, this version must be set to 3.15 or higher.
The version of the Stable ABI, both abi3 and abi3t, is indicated by
the Python wheel tag.
For example, a wheel tagged cp315-abi3.abi3t will be compatible with
3.15, 3.16, and later versions;
cp317-abi3.abi3t will be compatible with 3.17+.
Note that this PEP does not provide a way to target Stable ABI for
Free-threaded Python 3.14 and below (cp314-abi3t).
This may change an the future, or with experimental build tools, so
installers should be prepared for such extensions.
New API
Implementing this PEP will make it possible to build extensions that can be successfully loaded on free-threaded Python, but not necessarily ones that are thread-safe without a GIL.
Limited API to allow thread-safety without a GIL – presumably PyMutex,
PyCriticalSection, and similar – will be added via the C API working group,
or in a follow-up PEP.
Backwards and Forwards Compatibility
Extensions targetting abi3t will not be backwards-compatible with older
CPython releases, due to the need to use new PyModExport API added
in PEP 793.
Extension authors who cannot switch may continue to use the existing abi3,
that is, build on GIL-enabled Python without defining Py_GIL_DISABLED.
For compatibility with free-threaded builds, they can compile using
version-specific ABI – that is, compile abi3-compatible source
on free-threaded CPython builds without defining Py_LIMITED_API.
Limited API 3.15 for free-threading is a subset of the existing Limited API, and as such, it will be forward-compatible with future versions of CPython 3.x. Older versions of the Limited API (that is, 3.14 and below) will continue to be forward-compatible with GIL-enabled builds of CPython 3.x, starting with the version that introduced the given Limited API.
Compatibility Overview
The following table summarizes compatibility of wheel tags with CPython interpreters. “GIL” stands for GIL-enabled interpreter; “FT” stands for a free-threaded one.
| Wheel tag | 3.14 (GIL) | 3.14 (FT) | 3.15 (GIL) | 3.15 (FT) | 3.16+ (GIL) | 3.16+ (FT) |
|---|---|---|---|---|---|---|
cp314-cp314 |
✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
cp314-cp314t |
❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
cp314-abi3 |
✅ | ❌ | ✅ | ❌ | ✅ | ❌ |
cp314-abi3t (*) |
❌ | ✅ | ❌ | ✅ | ❌ | ✅ |
cp314-abi3.abi3t (*) |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
cp315-cp315 |
❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
cp315-cp315t |
❌ | ❌ | ❌ | ✅ | ❌ | ❌ |
cp315-abi3 |
❌ | ❌ | ✅ | ❌ | ✅ | ❌ |
cp315-abi3t |
❌ | ❌ | ❌ | ✅ | ❌ | ✅ |
cp315-abi3.abi3t |
❌ | ❌ | ✅ | ✅ | ✅ | ✅ |
(*): Wheels with these tags cannot be built; see table below
The following table summarizes which wheel tag should be used for an extension
built with a given interpreter and Py_LIMITED_API macro:
| To get the wheel tag… | Compile on… | Py_LIMITED_API |
Py_TARGET_ABI3T |
Note |
|---|---|---|---|---|
cp314-cp314 |
3.14 (GIL) | — | N/A | existing |
cp314-cp314t |
3.14 (FT) | — | N/A | existing |
cp314-abi3 |
3.14+ (GIL) | 3.14 | N/A | existing |
cp314-abi3t |
N/A | reserved | ||
cp314-abi3.abi3t |
N/A | reserved | ||
cp315-cp315 |
3.15 (GIL) | — | — | continued |
cp315-cp315t |
3.15 (FT) | — | — | continued |
cp315-abi3 |
3.15+ (GIL) | 3.15 | — | continued |
cp315-abi3t |
3.15+ | — | 3.15 | new |
| 3.15+ (FT) | 3.15 | — | ||
cp315-abi3.abi3t |
3.15+ | 3.15 | 3.15 | new |
In the “Compile on” column, FT means that the Py_GIL_DISABLED
macro must be defined – either explicitly or, on non-Windows platforms,
by including CPython headers configured with --disable-gil.
GIL means that Py_GIL_DISABLED must not be defined.
In the Py_LIMITED_API and Py_TARGET_ABI3T, a dash means the macro
must not be defined; a version means the macro must be set to the corresponding
integer in Py_PACK_VERSION() format.
Values in the Note column:
- existing: The wheel tag is currently in use
- continued: The wheel tag continues the existing scheme
- new: Proposed in this PEP.
- reserved: A mechanism to build a matching extension is not proposed in this PEP, but may be added in the future. Installers should be prepared to handle the tag.
Security Implications
None known.
How to Teach This
A porting guide will need to explain how to move to APIs added in
PEP 697 (Limited C API for Extending Opaque Types)
and PEP 793 (PyModExport).
Reference Implementation
This PEP combines several pieces, implemented individually:
- Opaque
PyObjectis available in CPython main branch after defining the_Py_OPAQUE_PYOBJECTmacro. Implemented in GitHub pull request python/cpython#136505. - For
PyModExport, see PEP 793 and GitHub issue #140550. - A version-checking slot was implemented in GitHub pull request python/cpython#137212.
- A check for older
abi3was implemented in GitHub pull request python/cpython#137957. - For wheel tags, there is no implementation yet.
- A porting guide is not yet written.
Rejected Ideas
Make PyObject opaque in Limited API 3.15
It would be possible to make PyObject struct opaque in Limited API 3.15
(that is, the new version of the existing Limited API),
rather than introduce a new variant of the Stable ABI and Limited API.
This would mean that extension authors would need to adapt their code to the new limitations, or abandon Limited API altogether, in order to use any C API introduced in Python 3.15.
It would also not remove the need for a new wheel tag (abi3t),
which would be required to express that an extension
is compatible with both GIL-enabled and free-threaded builds
of CPython 3.14 or lower.
Shims for compatibility with CPython 3.14
It’s possible to build a cp314-abi3.abi3t extension – one compatible
with 3.14 (both free-threaded build and default).
There are several challenges around this:
- making it convenient and safe for general extensions
- testing it (as CPython’s test suite doesn’t involve other CPython versions than the one being tested)
So, providing a mechanism to build such extensions is best suited to an external project (for example, one like pythoncapi-compat). It’s out of scope for CPython’s C API, and this PEP.
To sketch how such a mechanism could work:
The main issue that prevents compatibility with Python 3.14 is that with
opaque PyObject and PyModuleDef, it is not feasible to initialize
an extension module.
The solution, PEP 793, is only being added in Python 3.15.
It is possible to work around this using the fact that the 3.14 ABIs (both
free-threading and GIL-enabled) are “frozen”, so it is possible for an
extension to query the running interpreter, and for 3.14, use
a struct definition corresponding to the detected build’s PyModuleDef.
Naming this abi4
Instead of abi3t, we could “bump the version” and use abi4 instead.
The difference is largely cosmetic.
However, one thing this PEP does not propose is changing the filename
tag: extensions will be named with the extensions like .abi3.so.
Changing this while keeping compatibility with GIL-enabled builds would be
an unnecessary technical change.
Using abi3.abi4 in wheel tags but only .abi3 in filenames would
look more inconsistent than abi3.abi3t and .abi3.
If we added an abi4 tag, the Py_LIMITED_API value would either need to:
- change to start with
4to matchabi4, but no longer correspond toPY_VERSION_HEX(making it harder to generate and check), or - not change, making it inconsistent with
abi4.
Adding abi3t is a smaller change than adding abi4, making it work
better as a transitional state before larger changes like PEP 809’s
abi2026.
Reusing Py_GIL_DISABLED to enable the new ABI
It would be possible to select abi3t (rather than abi3) when the
Py_GIL_DISABLED macro is defined together with Py_LIMITED_API.
This would require annoying fiddling with build flags, and make it
especially cumbersome to target both abi3 and abi3t at the same time.
Making the new version of abi3 compatible with free-threading
It would be possible to make PyObject opaque in Limited API 3.15,
rather than add a new stable ABI.
This would make all extensions built for the Stable ABI 3.15 and above
compatible with both free-threading and GIL-enabled Python.
In the PEP discussion,
the ability to build for the GIL-only Stable ABI with no source changes
was deemed to be worth an extra configuration macro (Py_TARGET_ABI3T).
Copyright
This document is placed in the public domain or under the CC0-1.0-Universal license, whichever is more permissive.
Source: https://github.com/python/peps/blob/main/peps/pep-0803.rst
Last modified: 2026-01-23 22:49:04 GMT