Python
This guide explains how to install the Python recorder wheel, capture a trace with your own interpreter, and open the resulting recording in CodeTracer.
1. Install codetracer_python_recorder
-
Activate the environment that you normally use to run your Python code (virtualenv,
uv, Conda, system Python, etc.).ct recordalways reuses whichever interpreter is active in your shell. -
Install (or upgrade) the recorder package:
python -m pip install --upgrade codetracer_python_recorderIf you use a tool like
uvorpipx, run the equivalent command inside that tool so the recorder ends up on the samesys.pathas your application. -
Optional: confirm the module is reachable by asking the interpreter for help.
python -m codetracer_python_recorder --help
caution
If ct record cannot import codetracer_python_recorder, recording will fail with a module import error. Install the package in the interpreter you intend to trace or point Codetracer at a specific interpreter via CODETRACER_PYTHON_INTERPRETER=/path/to/python.
2. Record a trace
-
From the same shell where the interpreter (and recorder wheel) are available, run:
ct record path/to/script.py [-- <script arguments>]- Omit
--lang; Python scripts are auto-detected. - Any arguments after
--are passed directly to your script. - Use
CODETRACER_PYTHON_INTERPRETERif you need to force a specific interpreter (for example, inside CI).
- Omit
-
The command prints the trace identifier and the output directory (defaults to
., configurable with-o). The directory containstrace.json,trace_paths.json, andtrace_metadata.jsongenerated by the Python recorder via the db backend.
3. Open the trace
You can explore the recording immediately in the UI or later on:
-
Launch the GUI with the most recent trace:
ct replay -
Replay a specific Python trace by path:
ct replay --trace-folder path/to/trace-output -
Or jump straight from recording to replay in one command:
ct run path/to/script.py [-- <script arguments>]
All three commands reuse the recorded artefacts created by codetracer_python_recorder, so you see the exact execution captured during ct record.