memray

Memory profiler for Python by Bloomberg — tracks memory allocations and identifies memory leaks with flamegraph visualization. memray features: command-line memray run script.py, memray flamegraph output.bin, @memray.profile() decorator, live mode (memray run --live), memray stats for summary statistics, native mode for C extension tracking (--native), tracking of Python + native (C/C++) allocations, aggregated allocations view, temporal allocation timeline, thread-specific tracking, pytest plugin (pytest-memray), and Docker-friendly design. Finds memory leaks, unexpected allocations, and OOM root causes in Python services.

Evaluated Mar 06, 2026 (0d ago) v1.x
Homepage ↗ Repo ↗ Developer Tools python memray memory-profiling bloomberg profiling debugging performance flamegraph
⚙ Agent Friendliness
67
/ 100
Can an agent use this?
🔒 Security
90
/ 100
Is it safe for agents?
⚡ Reliability
82
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
85
Error Messages
80
Auth Simplicity
98
Rate Limits
98

🔒 Security

TLS Enforcement
92
Auth Strength
92
Scope Granularity
90
Dep. Hygiene
88
Secret Handling
88

memray output files contain allocation traces that may include memory content snapshots — treat output files as sensitive if profiling agents that handle secrets. --native mode requires elevated privileges (ptrace). No network calls during profiling.

⚡ Reliability

Uptime/SLA
85
Version Stability
82
Breaking Changes
80
Error Recovery
82
AF Security Reliability

Best When

Diagnosing Python memory leaks, OOM errors, or unexpected memory growth in agents, ML pipelines, and data processing scripts — memray's flamegraph visualization makes it immediately obvious which allocation path causes the problem.

Avoid When

You need CPU profiling (use py-spy), are on Windows, or need zero-overhead always-on production monitoring.

Use Cases

  • Agent memory leak detection — memray run --output=output.bin agent_script.py; memray flamegraph output.bin — generates interactive HTML flamegraph; agent developer identifies which function accumulates memory across 1000 agent iterations; Bloomberg-developed, production-tested on large Python services
  • Agent pytest memory regression — @pytest.mark.limit_memory('100 MB'); def test_agent_processing(): result = run_agent_on_large_dataset() — pytest-memray plugin enforces memory limit in test; agent CI pipeline fails if processing 10K records exceeds 100MB memory budget; catches memory regressions before production
  • Agent live memory monitoring — memray run --live agent_service.py — opens terminal dashboard showing real-time memory allocation by function; agent developer watches which function grows during load test; identifies leak source without stopping process
  • Agent native extension profiling — memray run --native ml_agent.py — tracks allocations in C extensions (numpy, torch) not just Python objects; agent ML pipeline OOM during inference tracked to PyTorch tensor buffer not Python objects; native mode essential for ML workloads
  • Agent programmatic profiling — with memray.Tracker('output.bin'): heavy_agent_function() — profile specific code section without full script; agent inline profiling wraps specific suspicious functions for targeted analysis without profiling entire agent startup

Not For

  • CPU profiling — memray is memory-only; for CPU profiling use py-spy or cProfile/viztracer
  • Windows — memray is Linux/macOS only; for Windows memory profiling use memory-profiler or tracemalloc
  • Production always-on profiling — memray overhead (10-30%) is too high for always-on production; use for targeted profiling sessions

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

No auth — local profiling tool.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

memray is Apache 2.0 licensed by Bloomberg. Free for all use.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • Output file grows large for long-running agents — memray run long_running_agent.py creates binary output tracking every allocation; 1-hour agent run can create 10GB+ output file; use memray run --aggregate for aggregated stats (no temporal data, smaller file) or memray run --trace-python-allocators only
  • Native mode requires ptrace permissions — memray run --native script.py on Linux may fail with 'Permission denied' if ptrace_scope > 1; agent Docker containers need --cap-add=SYS_PTRACE or run as root; native tracking essential for diagnosing OOM in PyTorch/NumPy C extensions
  • Live mode terminal requires TTY — memray run --live script.py requires interactive terminal; agent CI/CD systems without TTY raise error; use memray run without --live in CI and analyze output file separately with memray flamegraph
  • pytest-memray limit_memory is total not peak — @pytest.mark.limit_memory('50 MB') checks total bytes allocated not peak memory in use; agent tests with heavy allocate/deallocate cycles may fail limit even if peak RSS is low; use memray stats to distinguish peak from total allocations
  • Context manager requires explicit file path — with memray.Tracker('out.bin'): ... writes to file; without explicit path raises TypeError; agent inline profiling must specify output path: with memray.Tracker(f'/tmp/agent_profile_{time.time()}.bin'): run_agent()
  • flamegraph is localhost HTML not CLI — memray flamegraph output.bin opens browser or generates HTML file; agent CI pipeline must use memray flamegraph output.bin --output report.html for file output; default behavior opens browser which fails in headless CI

Alternatives

Full Evaluation Report

Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for memray.

AI-powered analysis · PDF + markdown · Delivered within 30 minutes

$99

Package Brief

Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.

Delivered within 10 minutes

$3

Score Monitoring

Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.

Continuous monitoring

$3/mo

Scores are editorial opinions as of 2026-03-06.

5229
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered