explaingit

bloomberg/memray

Analysis updated 2026-06-24 · repo last pushed 2026-05-21

15,019PythonAudience · developerComplexity · 3/5MaintainedSetup · moderate

TLDR

Memray is a memory profiler for Python from Bloomberg that records every allocation in Python and native C or C++ extensions, then produces flame graphs, tables, and live views.

Mindmap

mindmap
  root((memray))
    Inputs
      Python scripts
      Native extensions
      Running processes
    Outputs
      Flame graphs
      Tree views
      Live monitor
      Text summaries
    Use Cases
      Find memory leaks
      Cut peak RAM
      Debug native code
    Tech Stack
      Python
      C
      libunwind
      lz4
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Find a memory leak in a long-running Python service by running it under memray and inspecting the flame graph

USE CASE 2

Cut peak RAM usage in a data pipeline by tracing native NumPy or pandas allocations

USE CASE 3

Generate an HTML report attached to a CI job showing memory growth over a test run

USE CASE 4

Watch a live memory view of a misbehaving worker process to spot the leaking call site

What is it built with?

PythonCC++libunwindlz4

How does it compare?

bloomberg/memraycodelucas/newspaperandkret/cookbook
Stars15,01915,04315,082
LanguagePythonPythonPython
Last pushed2026-05-21
MaintenanceMaintained
Setup difficultymoderateeasyeasy
Complexity3/52/52/5
Audiencedeveloperdatadata

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Linux and macOS only, building from source needs libdebuginfod, libunwind, and lz4 development packages.

In plain English

Memray is a memory profiler for Python, built and open sourced by Bloomberg. A memory profiler watches a running program and records every time it asks the computer for memory, then helps you see where the memory went. The point is to answer questions like why is my program using so much RAM, or where is it leaking memory over time. Memray tracks allocations made from Python code, from native extension modules written in C or C++, and from the Python interpreter itself. It traces every function call rather than sampling at intervals, so the call stack in its reports reflects what actually happened. It also follows native calls into C and C++ libraries, so the full path of a memory allocation through both languages is visible. The README says the slowdown from profiling is small in pure Python mode and larger when tracking native code, and that this can be turned on or off on demand. It handles Python threads and threads created from native code. The tool runs only on Linux and macOS, it does not install on Windows. It needs Python 3.7 or newer and is installed from PyPI with pip install memray. The project ships binary wheels for common platforms, with build-from-source instructions covering libdebuginfod, libunwind, and lz4 dependencies. The main way to use it is the memray command line. You run your script under memray run, which writes a binary recording, and then you generate reports from that recording: an HTML flame graph, an HTML table, a tree view, a textual summary, or live monitoring. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Run a Python script under memray and produce an HTML flame graph showing the top allocating call sites
Prompt 2
Use memray live mode to attach to a running gunicorn worker on Linux and identify the heaviest allocations
Prompt 3
Compare two memray recordings of the same script before and after a refactor and quantify the memory delta
Prompt 4
Add a memray run to a pytest job so the build artifact includes a tree view of allocations for a target test
Prompt 5
Set up memray to track native allocations from a custom C extension and explain how the slowdown changes

Frequently asked questions

What is memray?

Memray is a memory profiler for Python from Bloomberg that records every allocation in Python and native C or C++ extensions, then produces flame graphs, tables, and live views.

What language is memray written in?

Mainly Python. The stack also includes Python, C, C++.

Is memray actively maintained?

Maintained — commit in last 6 months (last push 2026-05-21).

How hard is memray to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is memray for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.