memray
A memory profiler for Python applications
What it is and what it does
Memray is a memory profiler that instruments Python applications to capture every memory allocation, including calls into native C/C++ libraries. Unlike sampling profilers, it traces the full call stack, making it possible to pinpoint exactly where memory is being allocated and consumed. It works as both a command-line tool and a library, supporting Python threads and native threads in extensions.
The profiler generates multiple report formats—flame graphs, HTML tables, terminal trees, and summaries—to help developers analyze memory usage patterns, find leaks, and identify allocation hotspots. It's designed for production-like profiling with minimal overhead on Python code, though native code tracking incurs additional cost and can be toggled on demand.
Use it for:
- Identify the root cause of high memory consumption in a long-running Python application
- Detect memory leaks by comparing allocation patterns before and after suspected leak code
- Find hotspots in code that cause excessive allocations and optimize them
- Profile applications that use C/C++ extensions to understand memory behavior across language boundaries
- Analyze test suite memory usage with pytest-memray plugin to catch regressions
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Memray is a memory profiler for Python that traces every function call to track memory allocations across Python code, native extensions, and the interpreter itself, generating reports like flame graphs and tables to analyze memory usage.
Yes, if you develop on Linux or macOS and need to profile memory usage in Python applications. Memray's full call-stack tracing and native code support make it more precise than sampling profilers for finding leaks and allocation hotspots. Install friction is moderate (C extension, platform-limited), but prebuilt wheels and active maintenance reduce friction. No security vulnerabilities reported. Not suitable for Windows development.
Install
memray on PyPI
pip
pip install memrayuv
uv add memraypoetry
poetry add memrayInstalling memray
Before you install
Medium install friction due to C extension requiring compilation on some platforms. Active maintenance with recent releases (7 days since last update) and strong community engagement (15188 stars). Prebuilt wheels available for Linux x86/x64 and macOS; building from source requires libdebuginfod-dev, libunwind, and liblz4.
License in practice
Apache 2.0 permissive license allows commercial and private use with minimal restrictions, making it suitable for most projects without licensing concerns.
Quickstart
# Install
python3 -m pip install memray
# Profile a script
python3 -m memray run my_script.py
# Generate a flame graph
memray flamegraph memray-my_script.*.bin
Memray only works on Linux and macOS; cannot be installed on Windows or other platforms. Requires Python 3.9 or later.
Verify before relying
- Performance overhead when profiling native code compared to Python-only profiling
- Whether the live monitoring mode (memray live) requires specific network or environment setup
- Compatibility with async/await patterns and coroutine-based applications
Package facts
| License | Apache 2.0 (permissive) |
| Python support | supports the current Python release (>=3.9.0) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 3 — jinja2, rich, textual |
| Maintenance | actively maintained — 7 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 16,122,500/month — #1,160 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: memray-1.20.0-cp310-cp310-macosx_10_14_x86_64.whl; memray-1.20.0-cp310-cp310-macosx_11_0_arm64.whl; memray-1.20.0-cp310-cp310-manylinux2014_i686.manylinux_2_17_i686.whl; memray-1.20.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; memray-1.20.0-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl; memray-1.20.0-cp310-cp310-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl; memray-1.20.0-cp310-cp310-musllinux_1_2_x86_64.whl; memray-1.20.0-cp311-cp311-macosx_10_14_x86_64.whl; memray-1.20.0-cp311-cp311-macosx_11_0_arm64.whl; memray-1.20.0-cp311-cp311-manylinux2014_i686.manylinux_2_17_i686.whl; memray-1.20.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; memray-1.20.0-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl; memray-1.20.0-cp311-cp311-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl; memray-1.20.0-cp311-cp311-musllinux_1_2_x86_64.whl; memray-1.20.0-cp312-cp312-macosx_10_14_x86_64.whl; memray-1.20.0-cp312-cp312-macosx_11_0_arm64.whl; memray-1.20.0-cp312-cp312-manylinux2014_i686.manylinux_2_17_i686.whl; memray-1.20.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; memray-1.20.0-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl; memray-1.20.0-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Tags
More Debuggers packages
Extracts and displays stack frame and traceback…
permissive · top 1,000 on PyPI
debugpydebugpy is a Debug Adapter Protocol…
permissive · top 1,000 on PyPI
pylintPylint is a static code analyzer that checks…
copyleft · top 1,000 on PyPI
yamllintyamllint checks YAML files for syntax errors,…
copyleft · top 1,000 on PyPI
ipdbipdb is an IPython-enabled debugger that…
permissive · top 5,000 on PyPI
pyelftoolspyelftools parses and analyzes ELF binary files…
permissive · top 5,000 on PyPI
pytest-memrayA pytest plugin that integrates memray memory…
permissive · top 5,000 on PyPI
PymplerPympler measures, monitors, and analyzes memory…
permissive · top 5,000 on PyPI
py-spypy-spy is a sampling profiler that attaches to…
permissive · top 1,000 on PyPI
pystackPyStack inspects the stack frames of a running…
permissive · top 15,000 on PyPI
viztracerVizTracer traces Python code execution and…
permissive · top 5,000 on PyPI
pyinstrumentPyinstrument is a statistical call-stack…
permissive · top 5,000 on PyPI
scaleneScalene profiles Python code to measure CPU,…
permissive · top 15,000 on PyPI
pyroscope-ioPyroscope-io is a continuous profiling agent…
permissive · top 5,000 on PyPI
austin-distAustin is a frame stack sampler for CPython…
copyleft · top 5,000 on PyPI
line-profilerline_profiler measures execution time on a…
permissive · top 5,000 on PyPI