Yappi
A fast tracing Python profiler that is multithreading, asyncio, and gevent aware.
Repository Health
Technical Analysis
Yappi (Yet Another Python Profiler) is a tracing profiler for CPython that understands concurrency. Unlike the standard-library profilers, it correctly attributes CPU and wall-clock time across threads, asyncio coroutines, and gevent greenlets, so you can profile real concurrent applications without losing or misattributing time.
Implemented largely in C for low overhead, Yappi is imported into your program and controlled through a small API: start and stop profiling, then retrieve per-function and per-thread statistics that can be filtered, sorted, saved, and exported to callgrind or pstat formats for tools like KCachegrind and snakeviz. It supports both CPU-time and wall-time clocks, making it suitable for pinpointing both compute-bound and I/O-bound hotspots.
What You Get
- A tracing profiler that separates timing per thread, coroutine, and greenlet
- Selectable CPU-time and wall-clock timing modes
- Function and thread statistics with sorting, filtering, and clearing
- Export to callgrind and pstat formats for KCachegrind, snakeviz, and pstats
- A low-overhead C core suitable for profiling production-like workloads
Common Use Cases
- Profiling multithreaded Python services to find CPU hotspots per thread
- Measuring where time goes in asyncio or gevent applications
- Distinguishing I/O wait from compute using wall vs CPU clocks
- Exporting profiles to callgrind/pstat for visualization in external tools
Under The Hood
Architecture - The yappi/ package pairs a thin Python API (yappi.py) with a C extension core (_yappi.c) plus supporting C modules for call-stack tracking (callstack.c), timing (timing.c), thread-local storage (tls.c), a hash table (hashtab.c), and a freelist allocator (freelist.c). The C layer installs interpreter hooks and maintains per-context call graphs, which the Python layer exposes as function and thread stats objects.
Tech Stack - CPython C extension built via setup.py/pyproject.toml, with the public interface in pure Python. It targets modern CPython and integrates with asyncio and gevent context tracking.
Code Quality - The repo carries an extensive test suite under tests/ (async generators, context vars, asyncio context managers, and more) plus a CHANGELOG and manual test harnesses. The C core is modular and long-established, though maintenance cadence is intermittent.
API Design - The API is small and discoverable: module-level start/stop/clear_stats plus get_func_stats/get_thread_stats returning chainable, sortable stat collections. Clock selection and export helpers keep common workflows to a few lines, making it approachable despite the C internals.