Skip to main content

Intelligent Memory Leak Detective for Python

Project description

MemWatcher

PyPI version Python versions License: MIT

Intelligent Memory Leak Detective for Python

MemWatcher is a lightweight, easy-to-use Python library for detecting memory leaks in your applications. It monitors memory usage in real-time, analyzes patterns, and alerts you to potential leaks before they become critical issues.

Features

  • Lightweight & Fast - Minimal overhead, runs in background thread
  • Smart Detection - Statistical algorithms detect real leaks, not just growth
  • Beautiful Reports - Human-readable reports with actionable insights
  • Simple API - Decorators, context managers, or manual control
  • Framework Ready - Works with Django, FastAPI, Flask, and more
  • Real-time Monitoring - Continuous monitoring with customizable intervals
  • Configurable - Thresholds, sensitivity, callbacks - all customizable

Quick Start

Installation

pip install memwatcher

Basic Usage

from memwatcher import MemoryWatcher

# Start monitoring
watcher = MemoryWatcher(interval=5.0)
watcher.start()

# Your application code here
# ...

# Stop and get report
watcher.stop()
report = watcher.get_report()
print(report)

Using Decorators

from memwatcher import watch_memory, detect_leaks

@watch_memory(interval=1.0)
def process_large_dataset():
    # Your code here
    pass

@detect_leaks(sensitivity=0.1)
def long_running_task():
    # Your code here
    pass

Context Manager

from memwatcher import MemoryWatcher

with MemoryWatcher(interval=2.0) as watcher:
    # Your code here
    pass

# Report automatically generated
report = watcher.get_report()

Example Report

============================================================
MEMORY WATCHER REPORT
============================================================

Duration: 45.2s
Snapshots: 9

Memory Usage:
  Start:  145.23 MB
  End:    289.67 MB
  Change: +144.44 MB
  Peak:   289.67 MB
  Min:    145.23 MB

Leak Detection:
  Status: ⚠️  LEAK DETECTED
  Severity: MEDIUM
  Confidence: 87.3%
  Growth Rate: 3.197 MB/min
  Total Increase: 144.44 MB

Recommendation: Warning: Potential memory leak detected. Monitor closely.
============================================================

Use Cases

  • Development: Catch leaks during development before they hit production
  • Testing: Add memory checks to your test suite
  • Production: Lightweight monitoring in production environments
  • CI/CD: Automated leak detection in your pipeline
  • Profiling: Quick memory profiling for specific functions

Advanced Configuration

from memwatcher import MemoryWatcher

watcher = MemoryWatcher(
    interval=5.0,              # Snapshot every 5 seconds
    threshold_mb=500.0,        # Alert if exceeds 500MB
    enable_tracemalloc=True,   # Detailed tracking (higher overhead)
    callback=my_alert_function,# Custom callback on leak detection
    max_snapshots=100          # Keep last 100 snapshots
)

Documentation

Full documentation coming soon!

For now, check out the examples/ directory for more usage patterns.

Running Tests

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run with coverage
pytest --cov=memwatcher --cov-report=html

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details

Credits

Built by Yeakin Iqra


Star us on GitHub if MemWatcher helps you catch those sneaky memory leaks!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memwatcher-0.1.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

memwatcher-0.1.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file memwatcher-0.1.0.tar.gz.

File metadata

  • Download URL: memwatcher-0.1.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for memwatcher-0.1.0.tar.gz
Algorithm Hash digest
SHA256 05943f401842cca2fc70607347da15a78e2a3e852aaebb42fbb52fb7f783dc72
MD5 729f6dd61613c7e71a48188495956f68
BLAKE2b-256 9275d95c8e7aa79708c183089f21b6f8e45509460d7f679cd3153bbf91d33d0d

See more details on using hashes here.

File details

Details for the file memwatcher-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: memwatcher-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for memwatcher-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68e1bd17bae7cff0a3e73051eee4c337448ea187dfa2c4e375bf8806fca133c2
MD5 01b44c2f2b63677d5fb1018030d607f4
BLAKE2b-256 f22f57abbef693a4e3b27c2a8a5b3e2d7c5535a3e1ed34be555308270dd97566

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page