skillfed

memray

A memory profiler for Python applications

memray v1.20.0 16.1M downloads/30d#1,160 on PyPI15,188
Permissive license Apache 2.0 Active released

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 memray

uv

uv add memray

poetry

poetry add memray

Installing 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

Intended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseOperating System :: MacOSOperating System :: POSIX :: LinuxProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.15Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonTopic :: Software Development :: Debuggers

Tags

python memory profilermemory leak detectionallocation trackingflame graph generatornative code profilingmemory usage analysiscall stack tracing
profilingmemory-analysisdebugging

More Debuggers packages