| Crates.io | influxdb3 |
| lib.rs | influxdb3 |
| version | 0.1.3 |
| created_at | 2025-12-21 13:50:12.011445+00 |
| updated_at | 2025-12-29 22:23:18.090464+00 |
| description | InfluxDB 3 client library for rust |
| homepage | |
| repository | https://gitlab.com/rustfordevops/influxdb3.git |
| max_upload_size | |
| id | 1998010 |
| size | 75,912 |
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).
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
}