Professional memory profiler for Python with live tracking, CLI, and comprehensive export options.
Project description
๐ง MemProfilerX
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.
โจ What's New in v0.2.0
- ๐ฏ 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
๐ Features
Core Functionality
- ๐ฏ 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
Production Grade
- ๐ 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
๐พ Installation
pip install memprofilerx
Or using Poetry:
poetry add memprofilerx
Requires Python 3.12 or higher.
โ๏ธ Usage
Quick Start: Decorator API
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']}")
Global Process Tracking
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()
CLI: Profile Any Script
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.html
Interactive HTML Reports
Generate 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
Real-time Monitoring with Callbacks
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
๐ Output Examples
Decorator Output
{
"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}
}
}
CSV Format
timestamp_seconds,memory_mb
0.00,23.45
0.50,45.67
1.00,67.89
HTML Report
See example report - includes:
- Peak memory: 89.12 MB
- Average memory: 56.78 MB
- Duration: 5.23 seconds
- Interactive time-series chart
- Memory delta analysis
๐บ๏ธ Roadmap
โ Completed (v0.2.0)
- 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
๐ง In Progress
- Live dashboard (rich + curses)
- Memory diff between snapshots
- Integration with logging frameworks
- Prometheus exporter
- Sentry integration
- Memory flamegraphs
๐ฎ Future Ideas
- Memory leak detection algorithms
- Jupyter notebook integration
- VS Code extension
- Docker container profiling
- Comparative benchmarking tools
- AI-powered memory optimization suggestions
๐ ๏ธ Development
Setup Development Environment
# 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 Tests
# 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
Code Quality
# 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
Build Documentation
# Serve docs locally
poetry run mkdocs serve
# Build docs
poetry run mkdocs build
Release Process
- 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
๐ License
MIT License โ use it freely, improve it openly.
See LICENSE for full details.
๐ค Contributing
Contributions are welcome! We appreciate:
- ๐ Bug reports and fixes
- โจ Feature suggestions and implementations
- ๐ Documentation improvements
- ๐งช Test coverage improvements
- ๐ก Performance optimizations
Contribution Guidelines
- 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.
๐ Acknowledgments
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.
๐ Support
- ๐ Documentation
- ๐ Issue Tracker
- ๐ฌ Discussions
- ๐ฆ PyPI Package
Made with โค๏ธ by developers, for developers
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file memprofilerx-0.2.0.tar.gz.
File metadata
- Download URL: memprofilerx-0.2.0.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2103bd0df80db35bd827e86114e9f52bc16396401a7687c062772e6e9827df67
|
|
| MD5 |
ce36b866ec6e4e9f7a6cd30843fa97c3
|
|
| BLAKE2b-256 |
052a05edc9f905c50e6715c626463bb0912c11d91b55f613a1df93c9421988a5
|
Provenance
The following attestation bundles were made for memprofilerx-0.2.0.tar.gz:
Publisher:
ci.yml on NightzDev/memprofilerx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
memprofilerx-0.2.0.tar.gz -
Subject digest:
2103bd0df80db35bd827e86114e9f52bc16396401a7687c062772e6e9827df67 - Sigstore transparency entry: 911149343
- Sigstore integration time:
-
Permalink:
NightzDev/memprofilerx@bfac1bf432792e3e73e8304b099e350d52c5cc0b -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/NightzDev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@bfac1bf432792e3e73e8304b099e350d52c5cc0b -
Trigger Event:
push
-
Statement type:
File details
Details for the file memprofilerx-0.2.0-py3-none-any.whl.
File metadata
- Download URL: memprofilerx-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
378cc42861ce109ecb29b0a3b1f80ab2ea4baee326a3cd7e6ad0f9ca36f2f8e4
|
|
| MD5 |
ee8c2d8caa4ebaaaa9983222a80ff19a
|
|
| BLAKE2b-256 |
52e42d10faaa8d33cf84a2f5deee5dbc6b0dfec2d3836098b1af773f8e0912f2
|
Provenance
The following attestation bundles were made for memprofilerx-0.2.0-py3-none-any.whl:
Publisher:
ci.yml on NightzDev/memprofilerx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
memprofilerx-0.2.0-py3-none-any.whl -
Subject digest:
378cc42861ce109ecb29b0a3b1f80ab2ea4baee326a3cd7e6ad0f9ca36f2f8e4 - Sigstore transparency entry: 911149456
- Sigstore integration time:
-
Permalink:
NightzDev/memprofilerx@bfac1bf432792e3e73e8304b099e350d52c5cc0b -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/NightzDev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@bfac1bf432792e3e73e8304b099e350d52c5cc0b -
Trigger Event:
push
-
Statement type: