Watching data changes and record to list.
Project description
DataWatcher
A lightweight Python library for monitoring data changes and recording them to lists.
Features
- Monitor multiple data sources simultaneously
- Record data changes over time
- Thread-safe operations
- Simple and intuitive API
- Lightweight with zero dependencies
Installation
pip install datawatcher
Examples
Quick Start
from datawatcher import DataWatcher
import time
# Create a watcher instance
watcher = DataWatcher()
# Define a variable to monitor
counter = 0
# Register the variable for monitoring
watcher.watch(lambda: counter, "counter")
# Start monitoring (samples every 1 second by default)
watcher.start()
# Modify the variable
for i in range(10):
counter += 1
time.sleep(1.1)
# Stop monitoring
watcher.stop()
# Access recorded data
print(watcher["counter"]) # Print the recorded values
print(watcher.value_list("counter")) # Alternative way to get values
print(watcher.time_list()) # Get timestamps
System Resource Monitoring
Monitor CPU and memory usage over time:
from datawatcher import DataWatcher
import psutil # pip install psutil
import time
# Create watcher instance
watcher = DataWatcher()
# Register system metrics for monitoring
watcher.watch(lambda: psutil.cpu_percent(), "cpu_usage", callback=lambda x: print(x))
watcher.watch(lambda: psutil.virtual_memory().percent, "memory_usage")
# Start monitoring every 1 seconds
watcher.start(interval=1.0)
# Let it run for 10 seconds
print("Monitoring system resources for 10 seconds...")
time.sleep(10)
# Stop monitoring
watcher.stop()
# Display results
print("\n=== System Monitoring Results ===")
print(f"CPU Usage: {watcher['cpu_usage']}")
print(f"Memory Usage: {watcher['memory_usage']}")
print(f"Timestamps: {watcher.time_list()}")
API Reference
DataWatcher
Main class for monitoring data changes.
Methods
watch(func: Callable[[], Any], key: str, callback: Optional[Callable[[Any], Any]] = None)- Register a function to monitorunwatch(key: str)- Remove a monitored functionclear()- Clear all monitored functions and historystart(interval: float = 1.0)- Start monitoring with specified intervalstop()- Stop monitoringtime_list() -> List[float]- Get timestamp listvalue_list(key: str) -> List[Any]- Get recorded values for a key__getitem__(key: str) -> List[Any]- Access values using bracket notation
License
MIT License
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
datawatcher-0.1.0.tar.gz
(4.1 kB
view details)
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 datawatcher-0.1.0.tar.gz.
File metadata
- Download URL: datawatcher-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09e9bc1c61859c55d0249a531eac086eae21078115d3ddf96ecd1b72406807d5
|
|
| MD5 |
fa5469e4feb61a6e81267fdeb792721b
|
|
| BLAKE2b-256 |
9af289ad66b540b4da52912490cf8fb58c7b9a4c4a49ef256bd6d1327b96baa3
|
File details
Details for the file datawatcher-0.1.0-py3-none-any.whl.
File metadata
- Download URL: datawatcher-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40e94834e1a3009c37e9bf1ab9754e5453428acb3fbcdc38c7e6f023e6c49717
|
|
| MD5 |
0614c32a64564490f625c4119b3072ab
|
|
| BLAKE2b-256 |
915e415f2dc32c243172d0b3e025a29fd0119abd0778044d17ee29d3c0609705
|