Hi,
I just created C API: Meta issue to replace removed functions with new clean public functions to collaborate on this topic.
I plan to dedicate a large part of my time next months to add public C API functions and help projects to become compatible with Python 3.13. It’s an active project in my team to “port Fedora” for Python 3.13, the work just started last week (after alpha1 release). Cython is likely the first target, since it’s a very common dependency, and it is a good metric to see how things go with C API changes.
The internal C API usage and guidelines is not well defined so far. Exported functions should be usable outside Python, but there is no backward compatibility warranty.
I think that what you are describing is closer to PEP 689 – Unstable C API tier: unstable but supported API. For example, PyLongObject changed a lot in Python 3.12. PyUnstable_Long_IsCompact() and PyUnstable_Long_CompactValue() functions were added to the unstable API: you can use them, they are guaranteed to not change during Python 3.12.x lifecycle but they may change or be removed in Python 3.13.0 final release (in any 3.x.0 release): see the PEP for details.
We take more freedom regarding to “C99 style” in the internal C API. For example, we don’t fully support C++ in the internal API. Well, it’s a best effort support, if we can, we support C++, but not if it requires too much work.
Python is trying to support “explicitly” Cython for a long time: see for example [C API] Add explicit support for Cython to the C API · Issue #89410 · python/cpython · GitHub. The problem is that it’s a lot of work, and it seems like so far, nobody managed to provide a clean API for every single private/internal API usage made by Cython. It was more done on a case by case basis. Cython is different than other C extensions since it wants to be as fast or faster than CPython and for that “abuse” a lot of CPython internals. By “abuse”, I mean that Cython code is fragile and CPython cannot guarantee that it will not break. Adding APIs to abstract “a little bit” the relationship between CPython and Cython may reduce friction. Adding public documented and tested APIs is part of this work.
My plan is to add functions to https://pythoncapi-compat.readthedocs.io/ so it’s possible to write code compatible with old and new Python versions with a single code base. The most annoying part of Python 3 was that it was really hard to have a single code base working with Python 2 and Python 3.
There is also upgrade_pythoncapi.py tool which adds support for new Python versions, without losing support for old Python versions. I didn’t update the tool recently, it only handles some Python 3.12 changes.