Source-centric anomaly detection for timestamped sensor and MQTT data
Project description
anomaly-watcher
anomaly-watcher detects anomalies in timestamped sensor data with a rolling-window Isolation Forest pipeline. It includes a batch CLI and a local Streamlit dashboard for CSV, MQTT, and project-based monitoring.
Install
python -m pip install anomaly-watcher
The package requires Python 3.13 or newer. The project is licensed under AGPL-3.0-or-later.
Batch CLI
Both input files need a timestamp column and matching signal columns. Numeric, boolean, and categorical signals are supported; incomplete rows are discarded.
anomaly-watcher --train train.csv --test test.csv --output anomaly_overview.png
Useful options include:
--save-scores scores.csvwrites one score row per test window.--plot-sensor SENSORhighlights one signal in the overview plot.--window-seconds SECONDScontrols the rolling feature window.--stride-seconds SECONDScontrols the distance between windows.--threshold-mode max|quantile|stdselects threshold calculation.--forests-number NUMBERcontrols the Isolation Forest ensemble size.
Run anomaly-watcher --help for the complete option list.
anomaly-watcher-template copies the bundled CSV template into a target directory.
Dashboard
Launch the local dashboard with:
anomaly-watcher-dashboard
The dashboard creates a project folder containing:
project_config.jsonfor the project, source, model, and retraining configuration.sources/raw_<source-id>.jsonfor persisted source records.sources/features.json,sources/scores.json, andsources/anomalies.jsonfor derived results.model.joblibfor the trained model and scaler.
Each DataSource card keeps its configured name as its source ID. CSV sources can be reloaded from their configured file; MQTT sources can collect train, calibration, or test records; OPC UA is currently an adapter placeholder. MQTT passwords are requested at runtime and are not written to project configuration.
The Run page shows data requirements before training. The Monitoring page displays scaled features, scores, thresholds, and anomaly windows. Clearing source data removes persisted raw records and invalidates derived results while keeping the source card; deleting a source also removes its configuration.
Retraining preserves the original training and calibration records. New good test windows can be allocated as retrain-candidate or recalibrate-candidate, then promoted to retrain-used or recalibrate-used after a successful cycle. Supported allocation strategies are alternating, blocks, ratio, retrain_only, and recalibrate_only.
Bundled demo data
The package includes these fixtures under anomaly_watcher/resources/:
mock_training.csv: 500 normal records.mock_calibration.csv: 300 normal records.mock_test_v1.csv: 250 records with a climate anomaly.mock_test_v2.csv: 250 records with an air-quality anomaly.mock_test_v3.csv: 250 records with an equipment/pressure anomaly.
All fixtures use seven streams sampled every two seconds: room temperature, equipment temperature, humidity, CO2, ozone, air pressure, and VOC.
anomaly-watcher --train src/anomaly_watcher/resources/mock_training.csv --test src/anomaly_watcher/resources/mock_test_v1.csv --output mock_overview.png --save-scores mock_scores.csv --plot-sensor temperature_room --window-seconds 10 --stride-seconds 4 --forests-number 3 --relief-margin 0
Development and release
From the anomaly_watcher directory:
python -m pip install -e ".[test,release]"
python -m pytest tests/ -q
python -m build
python -m twine check dist/*
The current package version is 0.2.0. These commands build and validate the PyPI artifacts locally; uploading requires an explicit twine upload dist/* step and configured PyPI credentials.
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 anomaly_watcher-0.2.0.tar.gz.
File metadata
- Download URL: anomaly_watcher-0.2.0.tar.gz
- Upload date:
- Size: 1.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bbe213f821576ba90552b28ec12cd791485ba20e81d672f2b5a0fd00092e553
|
|
| MD5 |
3d161fc41d05f1c3b83dfcd3a46e6141
|
|
| BLAKE2b-256 |
c2eb5c3ee3029970a5a3682094a6794e132e1d4c04c50ed971bf8bbab888d5f8
|
Provenance
The following attestation bundles were made for anomaly_watcher-0.2.0.tar.gz:
Publisher:
anomaly-watcher-build-publish.yml on ricardo-cunha/python-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anomaly_watcher-0.2.0.tar.gz -
Subject digest:
1bbe213f821576ba90552b28ec12cd791485ba20e81d672f2b5a0fd00092e553 - Sigstore transparency entry: 2189831476
- Sigstore integration time:
-
Permalink:
ricardo-cunha/python-tools@d194967de6728d479cde848786cbc2be0670d156 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/ricardo-cunha
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
anomaly-watcher-build-publish.yml@d194967de6728d479cde848786cbc2be0670d156 -
Trigger Event:
push
-
Statement type:
File details
Details for the file anomaly_watcher-0.2.0-py3-none-any.whl.
File metadata
- Download URL: anomaly_watcher-0.2.0-py3-none-any.whl
- Upload date:
- Size: 1.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
160fb219144feb8f3920b0beabe105e7a8bc1d24b2cdcc110844594ee791f0f6
|
|
| MD5 |
ead1880c55c72bc90cb709ad97841a4e
|
|
| BLAKE2b-256 |
34de66cbbb7418f10fb61cd74d7a8a44ffcb71443a66afd69340021f82d21b29
|
Provenance
The following attestation bundles were made for anomaly_watcher-0.2.0-py3-none-any.whl:
Publisher:
anomaly-watcher-build-publish.yml on ricardo-cunha/python-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anomaly_watcher-0.2.0-py3-none-any.whl -
Subject digest:
160fb219144feb8f3920b0beabe105e7a8bc1d24b2cdcc110844594ee791f0f6 - Sigstore transparency entry: 2189831486
- Sigstore integration time:
-
Permalink:
ricardo-cunha/python-tools@d194967de6728d479cde848786cbc2be0670d156 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/ricardo-cunha
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
anomaly-watcher-build-publish.yml@d194967de6728d479cde848786cbc2be0670d156 -
Trigger Event:
push
-
Statement type: