Skip to content

gh-146636: Add Free-threaded Stable ABI migration guide#150580

Open
encukou wants to merge 22 commits into
python:mainfrom
encukou:abi3t-migration-sq
Open

gh-146636: Add Free-threaded Stable ABI migration guide#150580
encukou wants to merge 22 commits into
python:mainfrom
encukou:abi3t-migration-sq

Conversation

@encukou
Copy link
Copy Markdown
Member

@encukou encukou commented May 29, 2026

clin1234 and others added 20 commits May 17, 2026 05:33
This document provides detailed instructions on how to use the Free Threading Stable ABI in CPython, including guidelines for module initialization, API usage, and thread safety considerations.
Clarified access restrictions on PyObject members and recommended functions for type and reference count manipulation.
Clarified that direct access to PyObject members is prohibited.
Co-authored-by: da-woods <dw-git@d-woods.co.uk>
Updated documentation to clarify the identification of free-threaded limited API builds in C, including changes to macros and initialization methods.
Updated the documentation to clarify the use of the stable ABI and GIL management in Python extensions, including changes to member access and initialization methods.
Removed sections on API guidelines, critical sections, and thread safety from the documentation.
@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented May 29, 2026

Documentation build overview

📚 cpython-previews | 🛠️ Build #32906906 | 📁 Comparing 1448abd against main (26696a6)

  🔍 Preview build  

3 files changed
+ howto/abi3t-migration.html
± c-api/stable.html
± howto/index.html

=======

Note that when you build an extension compatible with multiple versions of
CPython, you should always *test* it witch each version it supports (for
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CPython, you should always *test* it witch each version it supports (for
CPython, you should always *test* it with each version it supports (for

@ngoldbaum
Copy link
Copy Markdown
Contributor

Thanks, this looks great! I'll probably use the tables in my EuroPython talk.

I'm hopeful that we'll be able to ship abi3t support in the next releases of PyO3 and Maturin (see PyO3/pyo3#5807 and PyO3/maturin#3113).

I am also planning to add a section to the free-threaded guide about building abi3t extensions, including practicalities like dealing with bindings generators and the NumPy C API. When that is ready, maybe we can just link there for all the ecosystem-wide details that don't belong in the CPython docs?

+-----------------+-------------------+------------------+
| 3.16 | ``cpython-316`` | ``cpython-316t`` |
+-----------------+-------------------+------------------+
| Future versions | (etc.) | (etc.) |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| Future versions | (etc.) | (etc.) |
| Future versions | ``cpython-X`` | ``cpython-Xt`` |

I suggest this to avoid the Latin abbreviation, which per the devguide we discourage.

+-----------------+ +------------------+
| 3.16 | | ``cpython-316t`` |
+-----------------+ +------------------+
| Future versions | | (etc.) |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| Future versions | | (etc.) |
| Future versions | | ``cpython-Xt`` |

Ditto.

resulting extension manually as well.
This is covered in :ref:`abi3t-migration-tagging` below.

This guide will ask you to do a series of changes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This guide will ask you to do a series of changes.
This guide will ask you to make a series of changes.

Unless you've done this step already, your extension module defines a
:ref:`module initialization function <extension-pyinit>`
named :samp:`PyInit_{<module_name>}`.
You will need to port it to :ref:`module export hook <extension-export-hook>`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You will need to port it to :ref:`module export hook <extension-export-hook>`,
You will need to port it to a :ref:`module export hook <extension-export-hook>`,


If there is some code before the ``return``, move it to
a :c:macro:`Py_mod_create` or :c:macro:`Py_mod_exec` slot function.
See :ref:`PyInit documentation <extension-pyinit>` for related information.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
See :ref:`PyInit documentation <extension-pyinit>` for related information.
See the :ref:`PyInit documentation <extension-pyinit>` for related information.

Leave out any fields that were missing (excexpt the new :c:macro:`Py_mod_abi`),
and substitute your own values.

See :c:type:`PySlot` and :c:ref:`export hook <extension-export-hook>`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
See :c:type:`PySlot` and :c:ref:`export hook <extension-export-hook>`
See the :c:type:`PySlot` and :c:ref:`export hook <extension-export-hook>`

- :c:func:`PyType_GetModuleByDef`

Check your code for these.
If you do not use them, you skip the rest of this section.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you do not use them, you skip the rest of this section.
If you do not use them, you can skip this section.

Comment on lines +351 to +352
if (PyModule_GetToken(module, &token) < 0) {
/* handle error */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (PyModule_GetToken(module, &token) < 0) {
/* handle error */
if (PyModule_GetToken(module, &token) < 0) {
/* handle error */

Hmm, the devguide actually doesn’t specify PEP 7/8 for code examples.

changes extensions may need.

If you find a problem that other extension authors might run into,
consider submitting an issue (or pull request) for this guide.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants