Skip to main content

A Python library for autonomous, explainable, real-time anomaly detection on time-series metrics

Project description

tsanomaly

A Python library for autonomous, explainable, real-time anomaly detection on time-series metrics.

pip install tsanomaly

Why tsanomaly

  • Zero configuration - seasonality, model choice, and the expected-range "envelope" are learned per metric.
  • Calibrated - envelope coverage is enforced by adaptive conformal inference; tail rarity comes from extreme value theory, not Gaussian assumptions.
  • Comparable scores - magnitude × duration × persistence, judged against the metric's own history: a 90 means the same rarity on any metric.
  • Regime-aware - a permanent level shift becomes one "new normal" finding and a re-anchored baseline, not endless alerts.
  • Incidents - concurrent anomalies group into one finding, ordered by who moved first: the root-cause hint.
  • Real-time - O(1) streaming updates, out-of-order tolerance, alert lifecycle with pluggable sinks, stall detection, checkpoint/restore.
  • Explainable - every anomaly carries its expected range, score breakdown, provenance, and a counterfactual.

Quickstart

import pandas as pd
import tsanomaly as tsa

# any long frame with metric / timestamp / value columns
history = pd.read_csv("payments.csv", parse_dates=["ts"])

det = tsa.Detector.auto()
det.fit(history)                      # learn normal, per metric
result = det.detect(new_data)         # scored, explained anomalies

print(result.summary())
for anomaly in result.alerts(min_score=70):
    print(anomaly.explain().to_text())

Output (NYC taxi ridership around the January 2015 blizzard):

learned seasonality: day (strength 0.67), week (strength 0.84)

`nyc.taxi.passengers` dropped to 7076 (expected 18060 to 25606)
    for 33.0 h starting 2014-11-27 05:30 UTC - score 100.   # Thanksgiving
`nyc.taxi.passengers` spiked to 23848 (expected 15488 to 19792)
    for 6.0 h starting 2015-01-18 09:30 UTC - score 100.    # MLK weekend
`nyc.taxi.passengers` dropped to 570 (expected 15629 to 22110)
    for 39.0 h starting 2015-01-26 11:30 UTC - score 100.   # blizzard travel ban
quickstart: NYC taxi ridership with detected anomalies

Examples

CNC mill vibration with the two Bosch-labeled bad cycles flagged

Documentation

  • Usage guide - data formats, batch & streaming APIs, configuration, persistence, incidents, events, feedback, evaluation utilities.
  • Architecture - the full pipeline.
  • Examples

How it works

 samples --> [ clean ] --> [ profile ] --> [ seasonality ] --> [ baseline ]
                                                                   |
                       expected value + self-calibrating envelope <--+
                                                                   |
             [ episodes ] <-- outside the envelope? <----------------+
                  |
                  +--> [ regime check ]  "new normal" vs anomaly
                  |
                  +--> [ score 0-100 ]   magnitude x duration x persistence
                            |
                            +--> [ incidents ]  related episodes, lead/lag
                            +--> [ explain ]    provenance + counterfactual

For more details, refer to docs/architecture.md.

Acknowledgements

The architecture of tsanomaly - autonomous per-metric baselines, anomaly scoring against a metric's own history, automatic seasonality detection, and condensing concurrent anomalies into incidents - is inspired by the system described in Anodot's published patents:

tsanomaly borrows the ideas and implements them with different, modern mechanisms - adaptive conformal calibration, extreme-value tail modeling, Bayesian online changepoint detection, harmonic-mean evidence combination, and effective-signal correction - detailed in docs/architecture.md.

License

Apache-2.0

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

tsanomaly-0.1.0.tar.gz (68.8 kB view details)

Uploaded Source

Built Distribution

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

tsanomaly-0.1.0-py3-none-any.whl (73.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tsanomaly-0.1.0.tar.gz
  • Upload date:
  • Size: 68.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tsanomaly-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1c508fcca428bfe344e8ccd8f3633073e073ba6d1f4d18de9d4c26164ef53a10
MD5 99960473d1722e60355db7afc5e1830b
BLAKE2b-256 ba2eb575f713bf632305c7e9b1bb61c75a698c39de4f36b942e4c7dbae59385e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tsanomaly-0.1.0.tar.gz:

Publisher: release.yml on visakhunnikrishnan/tsanomaly

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: tsanomaly-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 73.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tsanomaly-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec732309f5d73f739aeff13228c799364807a763dc4e751cdc4f5b69cb564f66
MD5 b9445d61d571004c640027e8c180804d
BLAKE2b-256 17105362a5b83dc86d572358e9f90cb085a971dbb6f0240bc3a9648abd245fb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for tsanomaly-0.1.0-py3-none-any.whl:

Publisher: release.yml on visakhunnikrishnan/tsanomaly

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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