{"id":2364,"library":"yappi","title":"Yet Another Python Profiler (Yappi)","description":"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.","status":"active","version":"1.7.6","language":"en","source_language":"en","source_url":"https://github.com/sumerc/yappi","tags":["profiling","performance","multithreading","asyncio","gevent","debugger"],"install":[{"cmd":"pip install yappi","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required Python version.","package":"python","version":">=3.6","optional":false}],"imports":[{"note":"The `_yappi` module is an internal C implementation detail and should not be imported directly. Attempting to do so or encountering an error related to `_yappi` often indicates an installation issue.","wrong":"from yappi import _yappi","symbol":"yappi","correct":"import yappi"}],"quickstart":{"code":"import yappi\nimport time\n\ndef calculate_sum(n):\n    total = 0\n    for i in range(n):\n        total += i\n    return total\n\ndef main_task():\n    time.sleep(0.1) # Simulate some I/O or other work\n    result = calculate_sum(1_000_000)\n    time.sleep(0.05)\n    return result\n\n# Start profiling\nyappi.set_clock_type(\"cpu\") # Can be \"wall\" for wall time\nyappi.start()\n\n# Run the code to be profiled\nmain_task()\n\n# Stop profiling and print statistics\nyappi.stop()\n\n# Get function statistics and print them\nfunc_stats = yappi.get_func_stats()\nprint(\"Function Statistics:\")\nfunc_stats.print_all(\n    columns={0:('ncall', 5), 1:('tottime', 8), 2:('avgtime', 8), 3:('file', 30)},\n    sort_type='tottime'\n)\n\n# Clear collected statistics\nyappi.clear_stats()","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade Python to 3.6+ or downgrade Yappi to a compatible older version if strict Python version requirements exist.","message":"Older versions of Yappi (pre-1.x) supported Python 2.6.x up to 3.4. Recent versions (from 1.7.0 onwards) officially support Python 3.6 and higher, including Python 3.14. Users on older Python 2 or early Python 3 versions will need to use an older Yappi release or upgrade their Python interpreter.","severity":"breaking","affected_versions":"<1.7.0"},{"fix":"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.","message":"Yappi operates as a per-interpreter resource. Attempting to run multiple Yappi profiler instances within the same Python interpreter concurrently will raise an exception.","severity":"gotcha","affected_versions":"All"},{"fix":"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.","message":"When interpreting profiling results, distinguish between 'tottime' and 'tsub'. 'tottime' (total time) includes time spent in sub-functions called from the profiled function, while 'tsub' (subtime) represents time spent directly within the function itself, excluding its sub-calls.","severity":"gotcha","affected_versions":"All"},{"fix":"Explicitly set the clock type using `yappi.set_clock_type(\"wall\")` before starting the profiler if Wall time is desired. Default is `\"cpu\"`.","message":"By default, Yappi profiles using 'CPU time'. For I/O-bound or concurrent applications (e.g., asyncio, gevent), 'Wall time' might be more relevant to capture actual elapsed time, including waits.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}