Skip to main content
The Rust SDK provides an ergonomic, type-safe interface for interacting with S2. It’s built on top of tokio for async I/O and offers first-class support for streams, batching, and backpressure.

Installation

Add the SDK to your Cargo.toml:
Or manually add to Cargo.toml:

Quick Start

Initialize the Client

Create an S2 client with your access token:
Generate an access token from the S2 dashboard.

List Basins

Retrieve all basins in your account:
For automatic pagination:

Working with Basins

Create a Basin

Get Basin Configuration

Reconfigure a Basin

Delete a Basin

Working with Streams

Get a Stream Handle

Create a Stream

List Streams

Writing Records

Using the Producer

The producer provides high-level batching and backpressure:
src/ops.rs:427-429

Direct Append

For more control, use the append API directly:

Append Session

For batch-level control with backpressure:

Reading Records

Read Session (Streaming)

For continuous reading with automatic pagination:
src/ops.rs:432-445

Single Read

For one-time reads:

Check Tail Position

src/ops.rs:391-395

Stream Management

Trim a Stream

Delete a Stream

Access Tokens

Issue a Token

List Tokens

Revoke a Token

Metrics

Account Metrics

Basin Metrics

Stream Metrics

Error Handling

All SDK operations return Result<T, S2Error>:

Configuration

Custom Endpoint

Retry Configuration

API Structure

The SDK is organized into three main types:
  • S2 - Account-level operations (basins, tokens, metrics)
  • S2Basin - Basin-level operations (streams, configuration)
  • S2Stream - Stream-level operations (append, read, trim)

Examples

The SDK includes comprehensive examples in the repository:
  • producer.rs - Producer pattern
  • consumer.rs - Consumer pattern
  • create_basin.rs - Basin creation
  • create_stream.rs - Stream creation
  • explicit_trim.rs - Stream trimming
  • list_all_basins.rs - Pagination example
  • And many more…
Run examples:

Resources

Crates.io

View package on Crates.io

Docs.rs

API reference documentation

Examples

Browse code examples

GitHub

Source code and issues

Next Steps