mcpbeat Sign in

Find Cpython Usage Agent Skill

> 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.

1k tokens
context cost
the whole folder, loaded on every use
1
files
instructions only
0
copies elsewhere
how many repositories repackaged it
646
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/DataDog/dd-trace-py --skill find-cpython-usage

The instruction itself

12 sections, as written by the author

Find CPython Internal Usage Skill

This skill helps identify all CPython internal headers and structures used in the

codebase, which is essential when adding support for new Python versions.

When to Use This Skill

Use this skill when:

  • Adding support for a new Python version
  • Investigating CPython API dependencies
  • Understanding what internal APIs the profiler uses
  • Preparing to compare CPython versions

Key Principles

  • Focus on internal headers - These are most likely to change between versions
  • Check all native extensions - CPython internals are used in profiling, AppSec, and internal modules
  • Look for struct field access - Direct field access is version-sensitive
  • Document findings - Keep track of what you find for comparison

How This Skill Works

Step 1: Find CPython Header Includes

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.

Step 2: Find Struct Field Access

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:

  • Frame structure access (PyFrameObject, _PyInterpreterFrame)
  • Thread state access (PyThreadState)
  • Code object access (PyCodeObject)
  • Generator/coroutine structures
  • Asyncio task structures

Step 3: Identify Common Structures

Common CPython structures we typically access:

Frame structures:

  • PyFrameObject / struct _frame
  • _PyInterpreterFrame

State structures:

  • PyThreadState
  • PyInterpreterState
  • _PyRuntimeState

Code structures:

  • PyCodeObject

Generator structures:

  • PyGenObject
  • PyAsyncGenASend

Asyncio structures:

  • FutureObj
  • TaskObj

Step 4: Document Findings

Create a list of:

  • All headers that are included
  • All structs that are accessed
  • All struct fields that are used directly

This will be used in the next step to compare against the new Python version.

Native Extensions Using CPython APIs

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.

Common Headers to Look For

The grep commands above will identify which CPython headers are actually used in the codebase.

Common patterns include:

Public Headers:

  • Headers matching *.h in Include/ directory (e.g., frameobject.h, unicodeobject.h)
  • Headers in Include/cpython/ directory (e.g., cpython/genobject.h)

Internal Headers (require Py_BUILD_CORE):

  • Headers matching internal/pycore*.h pattern
  • These are most likely to change between Python versions

Focus on headers that are actually found by the grep commands rather than maintaining

a hardcoded list, as the headers used may change over time.

Output Format

After running this skill, you should have:

  • A list of all CPython headers included in the codebase
  • A list of all CPython structs accessed
  • A list of struct fields accessed directly
  • Files that use each header/struct

This information can then be used with the compare-cpython-versions skill to identify what changed.

  • compare-cpython-versions skill: Use findings from this skill to compare versions

Other skills for the same job

different authors, same section of the catalogue
MCP Builder
by anthropics
vendor ×13

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

30k tokens scripts
Changelog Generator
by frostant
×9

Automatically creates user-facing changelogs from git commits by analyzing commit history, categorizing changes, and transforming technical commits into clear, customer-friendly release notes. Turns hours of manual changelog writing into minutes of automated generation.

774 tokens
Finishing A Development Branch
by ZhanlinCui
×7

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup

1k tokens
MCP Builder
by JayZeeDesign
×7

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

37k tokens scripts
Vercel React Native Skills
by vercel-labs
vendor ×6

React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.

39k tokens
Vercel React Best Practices
by ratacat
×5

React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.

34k tokens
Next Best Practices
by vercel-labs
vendor ×4

Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling

20k tokens
Using Git Worktrees
by ZhanlinCui
×4

Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification

1k tokens

How to use it

Copy the folder

Take datadog/find-cpython-usage from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

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.