Professional Python memory profiler โ Track, visualize, and analyze memory usage in real time with production-grade tools.
Modern, type-safe, and developer-friendly. From quick debugging to production monitoring.
- ๐ฏ CLI Tool:
memx run script.py- profile any script without code changes - ๐ Interactive HTML Reports: Beautiful reports with Plotly visualizations and statistics
- ๐ CSV Export: Export data for analysis in Excel, Google Sheets, or pandas
- ๐ Type Safety: Fully typed with strict mypy compliance
- ๐งช Production Ready: 90%+ test coverage, comprehensive error handling
- ๐ Professional Docs: Complete MkDocs documentation with guides and examples
- ๐ ๏ธ Better DX: Improved error messages, logging, and developer experience
- ๐ฏ Simple Decorators:
@track_memoryand@global_trackerfor zero-friction profiling - โก CLI Tool: Profile scripts with
memx run- no code modifications needed - ๐ Multiple Formats: Export to PNG, HTML, CSV, and JSON
- ๐ง GC Analysis: Deep inspection of live Python objects by type
- ๐ Real-time Tracking: Monitor memory as your code executes
- ๐ Callbacks: React to memory changes in real-time
- ๐ Type-safe: Full type hints with mypy strict mode
- ๐งช Well-tested: Comprehensive test suite (90%+ coverage)
- ๐ก๏ธ Robust: Proper error handling and logging
- โก Low Overhead: Minimal performance impact (~0.1-1% CPU)
- ๐ Documented: Complete documentation with examples
- ๐ CI/CD: Automated testing, linting, and releases
pip install memprofilerxOr using Poetry:
poetry add memprofilerxRequires Python 3.12 or higher.
from memprofilerx import track_memory
@track_memory(interval=0.5, analyze_gc=True)
def process_data():
data = [i * 2 for i in range(10_000_000)]
return sum(data)
result = process_data()
print(f"Result: {result['result']}")
print(f"Peak memory: {max(m for _, m in result['memory_usage']):.2f} MB")
print(f"Live objects: {result['live_objects']}")Monitor your entire application with all export formats:
from memprofilerx import global_tracker
@global_tracker(
interval=0.5,
export_png="memory.png", # Visualization
export_html="report.html", # Interactive report (via JSON + convert)
export_csv="memory.csv", # Spreadsheet data
export_json="memory.json" # Raw data
)
def main():
# Your application code
data = [i for i in range(10_000_000)]
process(data)
main()No code modifications needed - just use the CLI:
# Basic profiling with PNG output
memx run my_script.py
# Custom interval and HTML report
memx run my_script.py --interval 0.5 --format html --output report
# Export all formats at once
memx run my_script.py --format all --output analysis
# Convert existing JSON to other formats
memx convert memory.json --format html --output report.htmlGenerate beautiful, interactive reports:
from memprofilerx import global_tracker
from memprofilerx.reporter import export_to_html
import json
# Track with JSON export
@global_tracker(interval=0.3, export_json="memory.json")
def data_pipeline():
# Your code here
pass
data_pipeline()
# Convert to interactive HTML
with open("memory.json") as f:
data = json.load(f)
export_to_html(data, "report.html")The HTML report includes:
- ๐ Interactive Plotly charts
- ๐ Statistics (peak, average, min memory)
- ๐ Detailed timeline table with deltas
- ๐จ Beautiful dark theme UI
React to memory changes as they happen:
from memprofilerx import track_memory
import logging
def alert_on_high_memory(timestamp: float, memory: float) -> None:
if memory > 500: # 500 MB threshold
logging.warning(f"โ ๏ธ High memory: {memory:.2f} MB at {timestamp:.1f}s")
# Send alert, trigger GC, etc.
@track_memory(interval=1.0, callback=alert_on_high_memory)
def long_running_task():
# Your code
pass{
"result": 49999995000000,
"memory_usage": [
[0.0, 23.1],
[0.5, 130.5],
[1.0, 130.7]
],
"live_objects": {
"list": {"count": 10003, "total_size_kb": 400.2},
"dict": {"count": 12000, "total_size_kb": 800.5},
"int": {"count": 150000, "total_size_kb": 3200.1}
}
}timestamp_seconds,memory_mb
0.00,23.45
0.50,45.67
1.00,67.89See example report - includes:
- Peak memory: 89.12 MB
- Average memory: 56.78 MB
- Duration: 5.23 seconds
- Interactive time-series chart
- Memory delta analysis
- Memory tracking via decorator
- Graph export (PNG)
- GC object analysis
- Global process tracker
- CLI:
memx run my_script.py - Export to HTML and CSV
- Full type safety (mypy strict)
- Comprehensive test suite
- Professional documentation
- Live dashboard (rich + curses)
- Memory diff between snapshots
- Integration with logging frameworks
- Prometheus exporter
- Sentry integration
- Memory flamegraphs
- Memory leak detection algorithms
- Jupyter notebook integration
- VS Code extension
- Docker container profiling
- Comparative benchmarking tools
- AI-powered memory optimization suggestions
# Clone repository
git clone https://github.com/NightzDev/memprofilerx.git
cd memprofilerx
# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -
# Install dependencies
poetry install --with dev,docs
# Install pre-commit hooks
poetry run pre-commit install# Run all tests
poetry run pytest
# Run with coverage
poetry run pytest --cov
# Run specific test file
poetry run pytest tests/test_tracker.py
# Run with verbose output
poetry run pytest -v# Format code
poetry run black src tests
poetry run ruff format src tests
# Lint code
poetry run ruff check src tests
# Type check
poetry run mypy src
# Run all checks (what CI runs)
poetry run pre-commit run --all-files# Serve docs locally
poetry run mkdocs serve
# Build docs
poetry run mkdocs build- Update version in
pyproject.toml - Update
CHANGELOG.md - Create git tag:
git tag v0.2.0 - Push tag:
git push origin v0.2.0 - GitHub Actions will automatically publish to PyPI
MIT License โ use it freely, improve it openly.
See LICENSE for full details.
Contributions are welcome! We appreciate:
- ๐ Bug reports and fixes
- โจ Feature suggestions and implementations
- ๐ Documentation improvements
- ๐งช Test coverage improvements
- ๐ก Performance optimizations
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and linting (
poetry run pytest && poetry run ruff check) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
See CONTRIBUTING.md for detailed guidelines.
Built with:
- psutil - Cross-platform process utilities
- matplotlib - Visualization library
- rich - Beautiful terminal output
- typer - CLI framework
- pytest - Testing framework
Inspired by memory_profiler and Python's built-in tracemalloc.
- ๐ Documentation
- ๐ Issue Tracker
- ๐ฌ Discussions
- ๐ฆ PyPI Package
Made with โค๏ธ by developers, for developers