About this project

Memray is a memory profiler for Python designed to track memory allocations across Python code, native extension modules (like C/C++), and even the Python interpreter itself. It provides detailed call stack tracing for every function call, enabling accurate attribution of memory usage — unlike sampling profilers. It supports both CLI and library usage, making it flexible for different profiling scenarios. Key capabilities include: - Tracing all function calls with full call stack representation. - Profiling native C/C++ code within Python extensions (e.g., numpy, pandas) via optional --native flag. - Generating multiple report types: flame graphs (HTML), tables, tree views, live terminal monitoring, summaries, and stats. - Supporting Python threads and native threads (e.g., from C++ extensions). - Fast performance: minimal slowdown during profiling; native tracking can be toggled for speed vs. detail. - Integration with pytest via pytest-memray plugin for automated memory testing and limits. - Live mode: interactive TUI for real-time memory inspection during long-running scripts. - Programmable API: use memray.Tracker() context manager to profile specific code blocks programmatically. Installation requires Python 3.9+ and is available via pip or conda. Binary wheels are provided for Linux x86/x64 and macOS; source builds require system dependencies like libunwind and liblz4. Documentation and examples are hosted at https://bloomberg.github.io/memray/. Memray helps identify high memory usage, memory leaks, and allocation hotspots. It does not support Windows or other platforms. The project is Apache-2.0 licensed and welcomes community contributions following DCO sign-off.