Yappi (Yet Another Python Profiler) is a fast, C-implemented tracing profiler for Python applications, notably supporting multithreaded, asyncio, and gevent code. It overcomes limitations of standard profilers like `cProfile` by offering per-thread CPU time analysis, on-the-fly profiling capabilities, and flexible mechanisms for filtering and sorting profiling results. The library is currently at version 1.7.6 and maintains an active release schedule.
pip install yappiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to profile a simple Python function using `yappi.start()`, executing the target code, `yappi.stop()`, and then printing function statistics. It also shows how to set the clock type (CPU or Wall time) and clear the collected stats.
Upgrade Python to 3.6+ or downgrade Yappi to a compatible older version if strict Python version requirements exist.
Ensure only one `yappi.start()` is active at any given time per interpreter. Use `yappi.stop()` and `yappi.clear_stats()` between profiling sessions if necessary.
Understand the definitions: `tottime` is cumulative, `tsub` is self-time. Choose the appropriate metric based on whether you want to identify bottlenecks within a function's own execution or its entire call graph.
Explicitly set the clock type using `yappi.set_clock_type("wall")` before starting the profiler if Wall time is desired. Default is `"cpu"`.Run `pip install yappi` in your terminal to install the library.
On Debian/Ubuntu, install `python3-dev` using `sudo apt-get install python3-dev`. On Fedora, use `sudo dnf install python3-devel`. On macOS with Homebrew, ensure Python is installed with development headers (usually default).
Install the Microsoft Visual C++ Build Tools from the official Visual Studio download page (look for 'Build Tools for Visual Studio') and ensure the 'Desktop development with C++' workload is selected.
Call `save()` directly on the `YFuncStats` object returned by `yappi.get_func_stats()` (e.g., `stats = yappi.get_func_stats(); stats.save('profile.txt', type='callgrind')`).