Skip to main content

Lightweight Tracy profiler integration for Python

Project description

tracypy

A lightweight bridge from Python's sys.monitoring (PEP 669) to the Tracy profiler, as a plain-C extension module. Every Python function call becomes a Tracy zone, so you can see your program's call tree and timing in the Tracy viewer.

How it works

sys.monitoring delivers per-frame events; tracypy turns each frame's execution span into a Tracy zone. Entry events (PY_START / PY_RESUME / PY_THROW) begin a zone and exit events (PY_RETURN / PY_YIELD / PY_UNWIND) end it, pushed/popped on a per-thread stack. The callbacks are fast C functions; registration is the only part done in Python. Tracy is compiled in on-demand mode, so enabling tracypy is essentially free until a Tracy viewer connects.

The extension is built free-threading-ready (Py_MOD_GIL_NOT_USED), so it works on the free-threaded (no-GIL) builds of CPython too. Only Python function calls become zones — work inside C builtins or extension modules doesn't show up as its own zone. Each thread's zone stack is released when the process exits rather than when the thread does, so profiling a process that spawns unbounded short-lived threads grows memory slowly over time; for ordinary worker pools this is a non-issue.

Install

pip install tracypy        # or: uv pip install tracypy

Prebuilt wheels are published for CPython 3.13 and 3.14 (including the free-threaded 3.14t build) on Linux, macOS, and Windows, with the Tracy client statically linked — no toolchain or submodule needed. There is no source distribution, so on a platform or Python without a matching wheel, install from a Git checkout (below) instead.

From source

Building needs Python ≥ 3.13, a C/C++ toolchain, and CMake. The Tracy client is vendored as a git submodule, so clone recursively (or init the submodule), then install:

git submodule update --init        # if you didn't clone with --recurse-submodules
uv pip install .                   # or: pip install .

Usage

import tracypy

with tracypy.profile():
    my_workload()

Or run a script/module under the profiler without editing it:

python -m tracypy my_script.py [args...]
python -m tracypy -m my.module [args...]

profile() forwards its tool_id / name arguments to enable(). The low-level API is tracypy.enable(tool_id=PROFILER_ID, name="tracypy"), tracypy.disable(), and tracypy.is_enabled().

A runnable demo lives in examples/demo.py — connect a viewer, then:

TRACY_NO_EXIT=1 python -m tracypy examples/demo.py

Frames

Tracy frames delimit recurring units of work, so you can see per-unit timing statistics (min/max/avg, a frame-time graph) on top of the zone call tree. For web apps, for instance, a natural fit is "one frame per request":

import tracypy

# Discontinuous frame: an explicit span with a name of its own timeline.
with tracypy.frame("request"):
    handle(request)

For a Django app, drop in a middleware:

import tracypy

class TracyFrameMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        with tracypy.frame("request"):
            return self.get_response(request)

There's also a continuous-frame boundary marker, for the classic game-loop style where every tick is one frame:

tracypy.frame_mark()          # default frame boundary
tracypy.frame_mark("render")  # a named continuous frame

and the bare discontinuous primitives,

  • tracypy.frame_mark_start(name)
  • tracypy.frame_mark_end(name)

if the context manager doesn't fit.

Frame marks are independent of zone capture — they work whether or not enable() is on, and are inert until a viewer connects.

Viewing a trace

Download or build the Tracy profiler UI and Connect to localhost before (or while) your program runs. Because Tracy runs on-demand, nothing is captured until you connect.

tracypy vendors the Tracy client v0.13.1, so connect with a matching Tracy 0.13.x viewer — the network protocol is versioned, and a mismatched viewer won't connect.

For short scripts, the process may exit before the trace is fully sent. Try TRACY_NO_EXIT=1 so Tracy blocks at exit until the viewer has received everything:

TRACY_NO_EXIT=1 python -m tracypy my_script.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tracypy-0.13.1-cp314-cp314t-win_amd64.whl (257.4 kB view details)

Uploaded CPython 3.14tWindows x86-64

tracypy-0.13.1-cp314-cp314t-win32.whl (253.3 kB view details)

Uploaded CPython 3.14tWindows x86

tracypy-0.13.1-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (212.4 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

tracypy-0.13.1-cp314-cp314t-macosx_11_0_arm64.whl (128.4 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

tracypy-0.13.1-cp314-cp314-win_amd64.whl (257.4 kB view details)

Uploaded CPython 3.14Windows x86-64

tracypy-0.13.1-cp314-cp314-win32.whl (253.2 kB view details)

Uploaded CPython 3.14Windows x86

tracypy-0.13.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (212.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

tracypy-0.13.1-cp314-cp314-macosx_11_0_arm64.whl (128.3 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

tracypy-0.13.1-cp313-cp313-win_amd64.whl (249.1 kB view details)

Uploaded CPython 3.13Windows x86-64

tracypy-0.13.1-cp313-cp313-win32.whl (246.3 kB view details)

Uploaded CPython 3.13Windows x86

tracypy-0.13.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (212.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

tracypy-0.13.1-cp313-cp313-macosx_11_0_arm64.whl (128.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file tracypy-0.13.1-cp314-cp314t-win_amd64.whl.

File metadata

  • Download URL: tracypy-0.13.1-cp314-cp314t-win_amd64.whl
  • Upload date:
  • Size: 257.4 kB
  • Tags: CPython 3.14t, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for tracypy-0.13.1-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 771448c4324ec5144fe2bd515d457df996c759026e54505c0e567c6c149b8647
MD5 e17f849cef34607fbf17b06fcb931030
BLAKE2b-256 19a2db90ad500d65a641d47c74f28d8648988a1046013ce6b3731189d1ef4f02

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracypy-0.13.1-cp314-cp314t-win_amd64.whl:

Publisher: ci.yml on akx/tracypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracypy-0.13.1-cp314-cp314t-win32.whl.

File metadata

  • Download URL: tracypy-0.13.1-cp314-cp314t-win32.whl
  • Upload date:
  • Size: 253.3 kB
  • Tags: CPython 3.14t, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for tracypy-0.13.1-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 ac89ebe8b2485f3fc728a277fb85bf1c63824b5ddbdf1856922f0d78f303c79c
MD5 51449dfd3dc8f7e3aa7806a5184cb29e
BLAKE2b-256 7d16cbae770d1af8be6937ff54289742efe8121b49fb985df4ee0441eab1ac50

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracypy-0.13.1-cp314-cp314t-win32.whl:

Publisher: ci.yml on akx/tracypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracypy-0.13.1-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tracypy-0.13.1-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 075bf9a464f778e619dca756949b865308f6d246205f2f2f4c5c601045489406
MD5 b6d8e944599efd20124e64044948b32d
BLAKE2b-256 2835a9c5c99b2dad399f30db95945f1782ef4ccc39647bf5b0dafdffd280f8d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracypy-0.13.1-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: ci.yml on akx/tracypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracypy-0.13.1-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tracypy-0.13.1-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 850dfb4b01221b83c5041f74f1c44d595c8ca89546d626bb683b930321c19d41
MD5 f18446a556bc6582a2a26ed476b1af26
BLAKE2b-256 cdf538c1a3724832545f8ea2023c85878ff9585e6cdcf7ed0bce7c6c7dabf773

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracypy-0.13.1-cp314-cp314t-macosx_11_0_arm64.whl:

Publisher: ci.yml on akx/tracypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracypy-0.13.1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: tracypy-0.13.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 257.4 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for tracypy-0.13.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 77e49af8f860fd588998df994de93f33636226da936dfd9c8106976441c6c1cd
MD5 fe8b46a594016f6317c07673b0ee95f4
BLAKE2b-256 c7596d6698efcc3430499d43d860450171e145ec8f24592897eb68b250addbd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracypy-0.13.1-cp314-cp314-win_amd64.whl:

Publisher: ci.yml on akx/tracypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracypy-0.13.1-cp314-cp314-win32.whl.

File metadata

  • Download URL: tracypy-0.13.1-cp314-cp314-win32.whl
  • Upload date:
  • Size: 253.2 kB
  • Tags: CPython 3.14, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for tracypy-0.13.1-cp314-cp314-win32.whl
Algorithm Hash digest
SHA256 2575a7d8ba2acba1443a44cba4cc301257658f7123e3df5c8458e051f62da0ca
MD5 9f89db6da34f7d97ef6c0d8dff797fb4
BLAKE2b-256 b208ea115e738cae7dc626fede55ca546a45554b9ec741e593fdbf73675ca00a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracypy-0.13.1-cp314-cp314-win32.whl:

Publisher: ci.yml on akx/tracypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracypy-0.13.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tracypy-0.13.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9a4263be75087bc1f01cfe5e4ba7b7ba5abf35f25a04b4a872eda7e9c9d6aaf2
MD5 3bf98f7b9deba68b4b3aa44b60603c16
BLAKE2b-256 8989fd420744d898c7d75dc5277c6d23154da145527e6ebe258cdb3df16196fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracypy-0.13.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: ci.yml on akx/tracypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracypy-0.13.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tracypy-0.13.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a6937c69a2c97fc2e4bafce85686e1214558e92c357795f67a1ca451ddee46c3
MD5 abd671f3f3316810cbf9bca22c4eed11
BLAKE2b-256 b32816b8d5a71d43254b7a14c3dee04711a090ff4f2ed091ec5fe7601707d436

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracypy-0.13.1-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: ci.yml on akx/tracypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracypy-0.13.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: tracypy-0.13.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 249.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for tracypy-0.13.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2818ea49965d2f6af5e71d29e78510c268fabfed55ad9a8dd7265c1f3f83ea27
MD5 dd56193e94d56d16a17050b4e19e3177
BLAKE2b-256 43300f4e4ffb5eceb609e6676468ecb88b4a76c8c931fcf7a941a2a7f46373ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracypy-0.13.1-cp313-cp313-win_amd64.whl:

Publisher: ci.yml on akx/tracypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracypy-0.13.1-cp313-cp313-win32.whl.

File metadata

  • Download URL: tracypy-0.13.1-cp313-cp313-win32.whl
  • Upload date:
  • Size: 246.3 kB
  • Tags: CPython 3.13, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for tracypy-0.13.1-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 f4f7abc3523f279d6c8cc360426cdd96983e3ae3a58b182cebb3f30f5d49f23e
MD5 9ef3961fd4672c6e74ce1df216b69b54
BLAKE2b-256 647b63cee6c88a49d51c3de786f67c503688d3e1bc76a6bf74ed6fac03a3f52c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracypy-0.13.1-cp313-cp313-win32.whl:

Publisher: ci.yml on akx/tracypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracypy-0.13.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tracypy-0.13.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8f79b1b2cdc6f4bf9589f3a119e48010b66b32644433e1686f893a9e5e8f8a09
MD5 04f4f6294740a2222d3afb48023250ed
BLAKE2b-256 48c7ee806da91d8740e89b98b3494f2b956837dfa35b2b62bb3fea0495989dfb

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracypy-0.13.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: ci.yml on akx/tracypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracypy-0.13.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tracypy-0.13.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bb095ba84a9afb8b60383af7f0cf48d7abbc9924e47bb8176a0979b5b709d851
MD5 b9623844060f2206816a98e45beab858
BLAKE2b-256 c14c45b08f6775eda65a1e435ad98397ce5f5f96a86397db2fc5db8134360965

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracypy-0.13.1-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: ci.yml on akx/tracypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page