Skip to content

gh-149163: Add PyInitConfig API (PEP 741) to the limited C API#149194

Closed
anujbharambe wants to merge 6 commits intopython:mainfrom
anujbharambe:pyinitconfig-limited-api
Closed

gh-149163: Add PyInitConfig API (PEP 741) to the limited C API#149194
anujbharambe wants to merge 6 commits intopython:mainfrom
anujbharambe:pyinitconfig-limited-api

Conversation

@anujbharambe
Copy link
Copy Markdown

@anujbharambe anujbharambe commented Apr 30, 2026

Closes #149163 --> cc @vstinner

Summary

Add the PEP 741 PyInitConfig API to the limited C API / stable ABI, so programs embedding Python (GDB, Vim, PyInstaller, etc.) can use the modern initialization API without building against the full C API.

  • Create new top-level Include/initconfig.h following the pylifecycle.h / longobject.h pattern
  • Move the opaque PyInitConfig typedef and 14 function declarations out of Include/cpython/initconfig.h into the new header, guarded by Py_LIMITED_API >= 0x030f0000
  • Register 1 struct + 14 functions in Misc/stable_abi.toml
  • Regenerate PC/python3dll.c, Lib/test/test_stable_abi_ctypes.py, Doc/data/stable_abi.dat
  • Add versionchanged note to Doc/c-api/init_config.rst
  • Add changelog entry to Doc/whatsnew/3.15.rst

Internal types (PyConfig, PyPreConfig, PyStatus, PyWideStringList) remain excluded from the limited API.

The PyInitConfig API is the modern way for programs embedding Python
to initialize the interpreter. However, it was excluded from the
limited C API, forcing embedders to use deprecated legacy APIs or
build against the full (unstable) C API.

Create a new top-level `Include/initconfig.h` header (following the
established `pylifecycle.h` / `longobject.h` pattern) that exposes
the opaque `PyInitConfig` struct and all 14 associated functions to
limited API consumers targeting Python 3.15+.

The internal types (PyConfig, PyPreConfig, PyStatus, etc.) remain
excluded from the limited API.
@python-cla-bot
Copy link
Copy Markdown

python-cla-bot Bot commented Apr 30, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Apr 30, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@anujbharambe anujbharambe force-pushed the pyinitconfig-limited-api branch from 4475d41 to 4c0dd7c Compare April 30, 2026 21:06
Comment thread Doc/tools/.nitignore
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.

This is definitely wrong, there is no way this PR fixed all ~1000 issues. I assume something has broken, somewhere.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah you're right. The docs build was crashing before it could give any warnings. I have reverted the .nitignore changes and fixed the actual cause.

@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented Apr 30, 2026

Documentation build overview

📚 cpython-previews | 🛠️ Build #32491594 | 📁 Comparing 74e052b against main (5110738)

  🔍 Preview build  

16 files changed · ± 16 modified

± Modified

@anujbharambe
Copy link
Copy Markdown
Author

All checks are passing now, this should be good to go. cc @StanFromIreland

@vstinner
Copy link
Copy Markdown
Member

Ah. I planned to write a PR once we will get an agreement on the adding PEP 741 to the limited C API, especially get an approval of the C API Working Group. IMO this PR was created too soon, and I suggest closing it.

@anujbharambe
Copy link
Copy Markdown
Author

Got it, didn't realize this still needed the C API WG approval. Happy to close this for now. Let me know if this is useful as a reference once things are agreed on, happy to reopen or rework it then.

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.

Add PEP 741 PyInitConfig API to the limited C API

4 participants