Overview
I propose creating a standardized, machine-readable specification for managing deprecated and removed CPython APIs. This specification aims to improve tooling support, such as autofixers, by providing structured metadata.
Motivation
Currently, the lifecycle of CPython APIs, especially deprecations and removals, is documented in a human-readable format. This approach makes automated tooling challenging to implement. A structured, machine-readable approach will streamline tooling and automation around API usage.
(Well, I got a motivation from the language summit talk by @itamaro )
Proposal
Metadata Formats
Metadata will be maintained in two forms:
1. Source TSV File (deprecated_and_removed.tsv
)
Stored at the root of the CPython repository, structured as follows:
package
: Name of the module/package (e.g., āsysā, āasyncioā, āc-apiā)api
: Name of the API being deprecated or removedapi_type
: Type of API (function
,method
,class
,module
, orc-api
)status
: Status of API (deprecated
orremoved
)deprecated_at
: Version when API was deprecated (nullable)removed_at
: Version when API was removed (nullable)replacement
: Recommended replacement API (optional)
Example TSV:
package api api_type status deprecated_at removed_at replacement
sys getdefaultencoding function deprecated 3.12.0
asyncio Task.all_tasks method removed 3.8.0 3.10.0 asyncio.all_tasks
c-api PyEval_CallObject c-api removed 3.9.0 3.12.0 PyObject_Call
2. Generated JSON File (deprecated_and_removed.json
)
Automatically generated from the TSV file and made available via docs.python.org. Example JSON:
{
"_version": "3.14.1",
"_generated_at": "2025-05-15T00:00:00Z",
"apis": [
{
"package": "sys",
"api": "getdefaultencoding",
"api_type": "function",
"status": "deprecated",
"deprecated_at": "3.12.0",
"removed_at": null,
"replacement": null
},
{
"package": "asyncio",
"api": "Task.all_tasks",
"api_type": "method",
"status": "removed",
"deprecated_at": "3.8.0",
"removed_at": "3.10.0",
"replacement": "asyncio.all_tasks"
},
{
"package": "c-api",
"api": "PyEval_CallObject",
"api_type": "c-api",
"status": "removed",
"deprecated_at": "3.9.0",
"removed_at": "3.12.0",
"replacement": "PyObject_Call"
}
]
}
Generation and Distribution
- A Python script (
generate_api_metadata.py
) will read the TSV file and produce the JSON file. - The generated JSON file will be hosted as a static resource on
docs.python.org
. - JSON schema validation ensures correctness.
Integration with Sphinx Documentation
To include the JSON in Sphinx documentation:
Place the generated JSON file in the _static
directory, and update the conf.py
file:
The file becomes available at a stable URL like:
https://docs.python.org/3.14/_static/deprecated_and_removed.json
Benefits
- Enables automation tools to easily detect deprecated or removed APIs.
- Provides clarity and transparency about CPython API lifecycles.
Downside
- People should write duplicated information for the TSV file and docs.python.org RST file, but I believe that we can make consistency if we make an effort via tooling or something else.
Next Steps
- Feedback from the community regarding the approach and metadata structure.
- Write PEP if the idea looks good and implement a prototype tooling script.
- Integrate with the official Python documentation infrastructure.
Thank you for your feedback and ideas!
I would also like to mention people who may be interested in this idea. @vstinner and @hugovk