Expand description
§influxdb3-client
Async Rust client for InfluxDB 3 Core and InfluxDB 3 Enterprise.
Modelled after the official Go and Python clients: identical feature set, idiomatic Rust API.
§Quick start
use influxdb3_client::{Client, ClientConfig, Point, Precision};
#[tokio::main]
async fn main() -> influxdb3_client::Result<()> {
let client = Client::new(
ClientConfig::builder()
.host("https://cluster.example.io")
.token("my-api-token")
.database("sensors")
.build()?,
).await?;
// Write points: chain options, then await.
let points = vec![
Point::new("temperature")
.tag("location", "office")
.field("value", 22.5_f64)
.field("humidity", 48_i64),
];
client.write(points)
.precision(Precision::Millisecond)
.await?;
// Raw line protocol (low-level escape hatch)
client.write("cpu,host=srv1 usage=0.72").await?;
// Query with SQL. `.sql()` is shorthand for `.query(q, QueryType::Sql)`.
let result = client
.sql("SELECT * FROM temperature ORDER BY time DESC LIMIT 10")
.await?;
for row in result {
let row = row?;
println!("{} = {}", row["location"], row["value"]);
}
Ok(())
}§Streaming millions of rows
For results too large to materialise in memory, use .stream() on a query
builder. The gRPC channel is consumed lazily as batches are polled:
let mut stream = client.sql("SELECT * FROM huge_table").stream().await?;
while let Some(batch) = stream.try_next().await? {
// batch is an Arrow RecordBatch; process columns directly
println!("got {} rows", batch.num_rows());
}§High-throughput writes
For sustained ingest (flight-test telemetry, IIoT4.0 PLC streams), tune the batch size and inflight window:
client.write(points)
.batch_size(10_000)
.max_inflight(8)
.no_sync() // skip WAL sync for higher throughput
.gzip_threshold(None) // skip gzip on a fast LAN where bandwidth isn't the bottleneck
.await?;Re-exports§
pub use client::Client;pub use client::QueryRequest;pub use client::WriteRequest;pub use config::ClientConfig;pub use config::ClientConfigBuilder;pub use error::Error;pub use error::PartialWriteError;pub use flight::BatchStream;pub use point::FieldValue;pub use point::Point;pub use precision::Precision;pub use query::QueryIterator;pub use query::QueryParameters;pub use query::QueryResult;pub use query::QueryType;pub use query::Row;pub use query::Value;pub use retry::RetryConfig;pub use write::WriteInput;pub use write::WriteOptions;pub use write::DEFAULT_BATCH_SIZE;pub use write::DEFAULT_MAX_INFLIGHT;
Modules§
- client
- config
- error
- flight
- point
- precision
- query
- retry
- Retry policy and transient-failure classification.
- write
Type Aliases§
- Result
- Convenience alias for
std::result::Result<T, Error>.