datadog/find-cpython-usage
> Find all CPython internal headers and structs used in the codebase, particularly for profiling functionality. Use this when adding support for a new Python version to identify what CPython internals we depend on.
npx skills add https://github.com/DataDog/dd-trace-py --skill find-cpython-usage
This skill helps identify all CPython internal headers and structures used in the
codebase, which is essential when adding support for new Python versions.
Use this skill when:
Search for CPython header includes across all C/C++/Cython files:
# Find all CPython internal header includes
grep -r "include.*internal/pycore" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp" --include="*.pyx"
# Find all CPython cpython header includes
grep -r "include.*cpython" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp" --include="*.pyx"
# Find all Python.h includes (indicates CPython API usage)
grep -r "#include.*Python\.h" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp" --include="*.pyx"
# Find frameobject.h includes (common CPython API)
grep -r "#include.*frameobject\.h" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp" --include="*.pyx"
# Find PyO3 FFI usage in Rust (Rust extensions may use CPython internals)
grep -r "pyo3_ffi::\|pyo3::ffi::" src/native/ --include="*.rs" || true
Note: These patterns search across all native extension files (.c, .cpp, .h, .hpp, .pyx, .rs)
regardless of their location in the codebase. Check setup.py to see which extensions are built.
Rust extensions use PyO3 which may access CPython internals through the pyo3_ffi module.
Search for direct struct field access and struct definitions across all native files:
# Find struct field accesses (arrow operator)
grep -r "->f_\|->[a-z_]*\." ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp"
# Find struct definitions
grep -r "struct.*Py" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp"
# Find common CPython struct usage
grep -r "PyFrameObject\|PyThreadState\|_PyInterpreterFrame" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp" --include="*.pyx"
grep -r "PyFrameObject\|PyThreadState\|PyInterpreterState" src/native/ --include="*.rs" || true
# Find PyCodeObject usage
grep -r "PyCodeObject" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp" --include="*.pyx"
grep -r "PyCodeObject" src/native/ --include="*.rs" || true
Look for patterns like:
PyFrameObject, _PyInterpreterFrame)PyThreadState)PyCodeObject)Common CPython structures we typically access:
Frame structures:
PyFrameObject / struct _frame_PyInterpreterFrameState structures:
PyThreadStatePyInterpreterState_PyRuntimeStateCode structures:
PyCodeObjectGenerator structures:
PyGenObjectPyAsyncGenASendAsyncio structures:
FutureObjTaskObjCreate a list of:
This will be used in the next step to compare against the new Python version.
To find all native extensions that may use CPython APIs, check setup.py:
# View all native extensions defined in setup.py
grep -A 5 "Extension\|CMakeExtension\|Cython.Distutils.Extension\|RustExtension" setup.py
The setup.py file defines all native extensions (C, C++, CMake, Cython, and Rust) that
are built for the project. Not all extensions use CPython internals - focus on those
that access frame objects, thread state, or internal structures when searching for
CPython API usage.
Note: Rust extensions use PyO3 bindings which may access CPython internals through
pyo3_ffi module. Search Rust source files (.rs) for CPython API usage as well.
The grep commands above will identify which CPython headers are actually used in the codebase.
Common patterns include:
Public Headers:
*.h in Include/ directory (e.g., frameobject.h, unicodeobject.h)Include/cpython/ directory (e.g., cpython/genobject.h)Internal Headers (require Py_BUILD_CORE):
internal/pycore*.h patternFocus on headers that are actually found by the grep commands rather than maintaining
a hardcoded list, as the headers used may change over time.
After running this skill, you should have:
This information can then be used with the compare-cpython-versions skill to identify what changed.
Take datadog/find-cpython-usage from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.