#anomaly-detection #time-series #spot #ffi

libspot

Rust FFI bindings for libspot, a fast time series anomaly detector

3 releases

2.0.0-beta.6.0 Dec 18, 2025
2.0.0-beta.5.0 Sep 16, 2025
2.0.0-beta.3.0 Jul 11, 2025

#163 in Science

LGPL-3.0

64KB
1.5K SLoC

C 855 SLoC // 0.3% comments Rust 633 SLoC // 0.1% comments

libspot

Crates.io Documentation License: LGPL v3

A safe Rust wrapper (using FFI) for the libspot time series anomaly detection library.

Quick Start

use libspot::{SpotDetector, SpotConfig, SpotStatus};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create detector with default configuration
    let config = SpotConfig::default();
    let mut detector = SpotDetector::new(config)?;

    // Fit with training data
    let training_data: Vec<f64> = (0..1000)
        .map(|i| 5.0 + (i as f64 * 0.01).sin() * 2.0)
        .collect();
    detector.fit(&training_data)?;

    // Detect anomalies in real-time
    let test_value = 50.0; // This should be an anomaly
    match detector.step(test_value)? {
        SpotStatus::Normal => println!("Normal data point"),
        SpotStatus::Excess => println!("In the tail distribution"),
        SpotStatus::Anomaly => println!("Anomaly detected! 🚨"),
    }

    Ok(())
}

Alternative

For a pure Rust implementation without FFI dependencies, see the libspot-rs crate.

License

This project is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0).

Dependencies

~0.4–275KB