Pympler
Measure, monitor, and analyze the memory behavior of Python objects in a running application.
Repository Health
Technical Analysis
Pympler is a development toolkit for measuring, monitoring, and analyzing the memory behavior of Python objects in a running application. By instrumenting your program with Pympler, you gain detailed insight into the size and lifetime of objects, making it possible to pinpoint memory bloat and other unexpected runtime behavior that would otherwise be invisible.
Pympler unifies three previously separate projects into one comprehensive profiler: asizeof reports the actual memory footprint of one or more objects, muppy enables on-line monitoring of a live application, and the class tracker performs off-line analysis of the lifetime of selected objects. A web profiling frontend rounds it out with process statistics, garbage visualization, and class-tracker views. It is written entirely in Python with no external dependencies on Linux and macOS.
What You Get
- asizeof for accurate memory-footprint measurement of individual objects or collections
- muppy for on-line monitoring and heap snapshot diffing of a running application
- A class tracker for off-line analysis of the size and lifetime of selected object classes
- A web profiling frontend with process statistics and garbage visualization
- Pure-Python implementation with no external dependencies on Linux and macOS
Common Use Cases
- Diagnosing memory leaks and bloat in long-running Python services
- Measuring the true in-memory size of complex object graphs
- Tracking how many instances of a class exist and how long they live over time
Under The Hood
Architecture - Pympler is organized as a set of cooperating modules under pympler/. asizeof.py recursively walks object references to compute true memory footprints; muppy.py and summary.py enumerate and summarize live heap objects for on-line monitoring; classtracker.py with classtracker_stats.py records size and instance-count snapshots over time; and web.py with panels.py, charts.py, garbagegraph.py, and refgraph.py provide a web frontend with process stats and garbage/reference visualizations.
Tech Stack - Written entirely in Python (supporting 3.6 through 3.12+) with a py.typed marker. It has no third-party runtime dependencies on Linux and macOS; only Windows requires pywin32. Packaging uses setuptools via setup.py/setup.cfg/pyproject.toml, and the web frontend ships its own static assets and templates.
Code Quality - The repository includes a substantial test/ tree with subpackages for asizeof, muppy, tracker, gui, and process modules, plus a runtest.py harness, a mypy.ini for type checking, and a maintained CHANGELOG. It is a mature, established project; recent release cadence is low, but the codebase is stable and well structured.
API Design - Each subsystem exposes a focused API: asizeof.asizeof(obj) for sizing, muppy.get_objects() plus summary helpers for snapshots, and a ClassTracker object for lifetime tracking. The pieces can be used independently and incrementally, so a developer can start with a single asizeof call and adopt the heavier monitoring and web-frontend features only when needed.