Skip to content

Add sys.abi_info to make information about the interpreter ABI more accessible #133143

Description

@zklaus

Feature or enhancement

Proposal:

Early on in the discussion of PEP 780: ABI features as environment markers a certain shortcoming of ABI information availability was identified and discussed.
One suggestion was to adopt a new mechanism for making this kind of information available, which initially was included as a proposal in PEP 780 itself. However, that PEP is aimed at improving the packaging situation and to improve that focus, the addition to the standard library is no longer part of it.

Here, we propose to add ABI information to the standard library in the form of a new attribute to the sys module.

In PEP 780 three ABI features are identified, namely

  • free-threading or gil-enabled (only CPython)
    If the Python interpreter is free-threaded, the free-threading feature MUST be present and the gil-enabled feature MUST NOT be present. Otherwise, the gil-enabled feature MUST be present and the free-threading feature MUST NOT be present.

  • debug (only CPython, optional)
    This ABI feature is reserved for the --with-pydebug build of CPython. If the interpreter is a CPython interpreter with Py_DEBUG capabilities, the debug feature MUST be present. On POSIX systems, this corresponds to the Python expression "d" in sys.abiflags.

  • 32-bit or 64-bit (optional)
    The bitness of the interpreter, that is, whether it is a 32-bit or 64-bit build. If the bitness is unknown or neither 32-bit nor 64-bit, this feature MUST NOT be present.

A reference implementation of this feature is available, which adds these features as a frozen set of identifying strings to sys.abi_features.

For purposes of the environment markers defined in PEP 780, only the presence or absence of the features is relevant. However, in the discussion of the reference implementation @FFY00 suggested that a more comprehensive implementation might be useful, for example providing additional information about the ABI features, such as their representation in sys.abiflags (which directly impacts their possible representation in the ABI tags used for wheels and extension modules), or their default state.

This addition to the standard library will make crucial ABI information much easier to access.

We think this fully backwards compatible addition can be made with a simple pull request.

It would be great to hear from the CPython team.

Do you agree that this is a useful feature?

Do you think detailed information beyond simple presence or absence of ABI features should be included?

Do you have suggestions for the exact API?

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

Initial thoughts on this feature, have surfaced in the discussions leading to PEP 780.
During the discussion of the PEP, further comments were made, leading to the separation from the PEP with further review comments available.

Linked PRs

Activity

  1. merwok commented on Apr 29, 2025

    @merwok
    Member

    Hello, I think this discussion should happen on the forums to get better visibility from the core devs.

  2. zklaus commented on Apr 30, 2025

    @zklaus
    ContributorAuthor

    Thanks for your feedback, @merwok. As you can see from the description, there have been a few discussions on the forum already; this is an effort to drive things closer to implementation.

    I hope that makes sense?

  3. merwok commented on Apr 30, 2025

    @merwok
    Member

    Sure, but few Python core devs read all the packaging threads, so discuss is still the place to discuss changes like this before implementing.

  4. ngoldbaum commented on Jun 18, 2025

    @ngoldbaum
    Contributor

    Hello, I think this discussion should happen on the forums to get better visibility from the core devs.

    See https://discuss.python.org/t/add-sys-abi-features-to-make-information-about-the-interpreter-abi-more-accessible/94422

  5. added a commit that references this issue on Sep 8, 2025
  6. encukou commented on Sep 8, 2025

    @encukou
    Member

    I noticed a possible small refactoring sysmodule.c (for a follow-up PR because it will also touch some existing code):

    • Instead of PyUnicode_FromString("...") (with a literal string), use &_Py_ID(...) (a static immortal constant; note that there are no quotes)
      • some of these are behind the SET_SYS_FROM_STRING macro
    • Run make regen-global-objects to generate code for new _Py_IDs
  7. reopened this on Sep 8, 2025
  8. added a commit that references this issue on Sep 8, 2025
  9. added 2 commits that reference this issue on Sep 9, 2025
  10. added 3 commits that reference this issue on Sep 9, 2025
  11. changed the title [-]Add `sys.abi_features` to make information about the interpreter ABI more accessible[/-] [+]Add `sys.abi_info` to make information about the interpreter ABI more accessible[/+] on Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions