influxdb3

Crates.ioinfluxdb3
lib.rsinfluxdb3
version0.1.3
created_at2025-12-21 13:50:12.011445+00
updated_at2025-12-29 22:23:18.090464+00
descriptionInfluxDB 3 client library for rust
homepage
repositoryhttps://gitlab.com/rustfordevops/influxdb3.git
max_upload_size
id1998010
size75,912
Romain S. (romzorus)

documentation

README

InfluxDB 3 bindings for Rust

This crate helps to bind the Rust ecosystem with InfluxDB 3 REST API. Based on reqwest, it requires an async context to work (for now).

Example

use chrono::NaiveDateTime;
use influxdb3::{DataPointBuilder, FieldDataType};
use influxdb3::InfluxDbClientBuilder;
use serde::Deserialize;

#[tokio::main]
async fn main() {

    // CONNECTING
    let influxdb_client = InfluxDbClientBuilder::new()
        .with_server_endpoint("http://localhost:8181")
        .with_token("<a-very-long-token>")
        .database("weather")
        .build()
        .unwrap();


    // WRITING
    let data_point = DataPointBuilder::new()
        .table("France")
        .with_tag("city", "Paris")
        .with_tag("district", "second")
        .with_tag("sensor_id", "XKCD722")
        .with_field("temperature", FieldDataType::Float(19.78))
        .with_field("hygrometry", FieldDataType::Integer(51))
        .datetime(
            NaiveDateTime::parse_from_str("2025-12-22T21:10:59.126", "%Y-%m-%dT%H:%M:%S%.3f")
                .unwrap()
                .and_utc(),
        )
        .build()
        .unwrap();

    match influxdb_client.write_one(data_point).await {
        Ok(cluster_uuid_opt) => {
            println!("Writing successful : cluster_uuid = {:?}", cluster_uuid_opt);
        }
        Err(error_detail) => {
            println!("Failure : {:?}", error_detail);
        }
    }

    // READING
    match influxdb_client.query_sql("SELECT time,temperature,hygrometry FROM 'France'").await {
        Ok(response_value) => {
            match serde_json::from_value::<Vec<ReceivedDataPoint>>(response_value) {
                Ok(data_points) => {
                    println!("Response : {:#?}", data_points);
                }
                Err(error_details) => {
                    println!("Failure to parse content : {:?}", error_details);
                }
            }
        }
        Err(error_detail) => {
            println!("Failure : {:?}", error_detail);
        }
    }
}

#[derive(Debug, Deserialize)]
struct ReceivedDataPoint {
    time: String,
    temperature: f64,
    hygrometry: i64
}

TODO list (unordered)

  • Allow to use all parameters available when writing
  • Add functions to check InfluxDb server's health and gather informations on it
Commit count: 0

cargo fmt