Skip to main content

influxdb3_client/
lib.rs

1//! # influxdb3-client
2//!
3//! Async Rust client for **InfluxDB 3 Core** and **InfluxDB 3 Enterprise**.
4//!
5//! Modelled after the official
6//! [Go](https://github.com/InfluxCommunity/influxdb3-go) and
7//! [Python](https://github.com/InfluxCommunity/influxdb3-python) clients:
8//! identical feature set, idiomatic Rust API.
9//!
10//! ## Quick start
11//!
12//! ```rust,no_run
13//! use influxdb3_client::{Client, ClientConfig, Point, Precision};
14//!
15//! #[tokio::main]
16//! async fn main() -> influxdb3_client::Result<()> {
17//!     let client = Client::new(
18//!         ClientConfig::builder()
19//!             .host("https://cluster.example.io")
20//!             .token("my-api-token")
21//!             .database("sensors")
22//!             .build()?,
23//!     ).await?;
24//!
25//!     // Write points: chain options, then await.
26//!     let points = vec![
27//!         Point::new("temperature")
28//!             .tag("location", "office")
29//!             .field("value", 22.5_f64)
30//!             .field("humidity", 48_i64),
31//!     ];
32//!     client.write(points)
33//!         .precision(Precision::Millisecond)
34//!         .await?;
35//!
36//!     // Raw line protocol (low-level escape hatch)
37//!     client.write("cpu,host=srv1 usage=0.72").await?;
38//!
39//!     // Query with SQL. `.sql()` is shorthand for `.query(q, QueryType::Sql)`.
40//!     let result = client
41//!         .sql("SELECT * FROM temperature ORDER BY time DESC LIMIT 10")
42//!         .await?;
43//!
44//!     for row in result {
45//!         let row = row?;
46//!         println!("{} = {}", row["location"], row["value"]);
47//!     }
48//!
49//!     Ok(())
50//! }
51//! ```
52//!
53//! ## Streaming millions of rows
54//!
55//! For results too large to materialise in memory, use `.stream()` on a query
56//! builder.  The gRPC channel is consumed lazily as batches are polled:
57//!
58//! ```rust,no_run
59//! # use influxdb3_client::Client;
60//! # use futures_util::TryStreamExt;
61//! # async fn example(client: &Client) -> influxdb3_client::Result<()> {
62//! let mut stream = client.sql("SELECT * FROM huge_table").stream().await?;
63//! while let Some(batch) = stream.try_next().await? {
64//!     // batch is an Arrow RecordBatch; process columns directly
65//!     println!("got {} rows", batch.num_rows());
66//! }
67//! # Ok(()) }
68//! ```
69//!
70//! ## High-throughput writes
71//!
72//! For sustained ingest (flight-test telemetry, IIoT4.0 PLC streams), tune the
73//! batch size and inflight window:
74//!
75//! ```rust,no_run
76//! # use influxdb3_client::{Client, Point};
77//! # async fn example(client: &Client, points: Vec<Point>) -> influxdb3_client::Result<()> {
78//! client.write(points)
79//!     .batch_size(10_000)
80//!     .max_inflight(8)
81//!     .no_sync()                  // skip WAL sync for higher throughput
82//!     .gzip_threshold(None)       // skip gzip on a fast LAN where bandwidth isn't the bottleneck
83//!     .await?;
84//! # Ok(()) }
85//! ```
86
87pub mod client;
88pub mod config;
89pub mod error;
90pub mod flight;
91pub mod point;
92pub mod precision;
93pub mod query;
94pub mod retry;
95pub mod write;
96
97#[cfg(feature = "polars")]
98pub mod write_dataframe;
99
100pub use client::{Client, QueryRequest, WriteRequest};
101pub use config::{ClientConfig, ClientConfigBuilder};
102pub use error::{Error, PartialWriteError};
103pub use flight::BatchStream;
104pub use point::{FieldValue, Point};
105pub use precision::Precision;
106pub use query::{QueryIterator, QueryParameters, QueryResult, QueryType, Row, Value};
107pub use retry::RetryConfig;
108pub use write::{WriteInput, WriteOptions, DEFAULT_BATCH_SIZE, DEFAULT_MAX_INFLIGHT};
109
110/// Convenience alias for `std::result::Result<T, Error>`.
111pub type Result<T> = std::result::Result<T, Error>;