| Crates.io | flowglad |
| lib.rs | flowglad |
| version | 0.1.1 |
| created_at | 2025-10-12 03:27:50.995202+00 |
| updated_at | 2025-10-12 03:31:51.62507+00 |
| description | (Unofficial) Rust SDK for FlowGlad - Open source billing infrastructure |
| homepage | https://flowglad.com |
| repository | https://github.com/hdresearch/flowglad-rs |
| max_upload_size | |
| id | 1878825 |
| size | 192,327 |
A Rust client library for the FlowGlad billing API.
FlowGlad is an open-source billing infrastructure platform. This library provides a type-safe, ergonomic Rust interface to the FlowGlad API, with support for:
Add this to your Cargo.toml:
[dependencies]
flowglad = "0.1"
tokio = { version = "1", features = ["full"] }
use flowglad::{Client, Config};
use flowglad::types::customer::CreateCustomer;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the client
let config = Config::new("sk_test_your_api_key");
let client = Client::new(config)?;
// Create a customer
let customer = client
.customers()
.create(
CreateCustomer::new("user_123", "Jane Doe")
.email("jane@example.com")
)
.await?;
println!("Created customer: {}", customer.id);
// Retrieve the customer by external ID
let retrieved = client.customers().get("user_123").await?;
println!("Retrieved: {}", retrieved.name.unwrap_or_default());
Ok(())
}
use flowglad::Config;
let config = Config::new("sk_test_your_api_key");
use flowglad::Config;
// Reads from FLOWGLAD_API_KEY environment variable
let config = Config::from_env()?;
use flowglad::Config;
use std::time::Duration;
let config = Config::builder()
.api_key("sk_test_your_api_key")
.timeout(Duration::from_secs(60))
.max_retries(5)
.build()?;
The library uses Rust's type system to prevent common mistakes:
use flowglad::types::customer::CreateCustomer;
// Compile-time enforcement of required fields
let customer = CreateCustomer::new("external_id", "customer_name")
.email("optional@email.com")
.phone("+1-555-0123");
Comprehensive error types for robust error handling:
use flowglad::Error;
match client.customers().get("user_123").await {
Ok(customer) => println!("Found: {}", customer.id),
Err(Error::Api { status, message, .. }) => {
eprintln!("API error {}: {}", status, message);
}
Err(Error::Network(e)) => {
eprintln!("Network error: {}", e);
}
Err(Error::RateLimit { retry_after }) => {
eprintln!("Rate limited. Retry after: {:?}", retry_after);
}
Err(e) => {
eprintln!("Error: {}", e);
}
}
The client automatically retries failed requests with exponential backoff for:
Configurable via Config::builder().max_retries().
Store custom key-value data with any resource:
use serde_json::json;
let customer = client
.customers()
.create(
CreateCustomer::new("user_123", "Jane Doe")
.metadata("plan", json!("premium"))
.metadata("tier", json!(3))
.metadata("features", json!(["api_access", "sso"]))
)
.await?;
The examples/ directory contains comprehensive examples:
basic_customers.rs - CRUD operations for customerscustomer_metadata.rs - Working with metadataerror_handling.rs - Robust error handling patternsRun an example with:
FLOWGLAD_API_KEY=sk_test_... cargo run --example basic_customers
client.customers().create() - Create a new customerclient.customers().get() - Retrieve a customer by external IDclient.customers().update() - Update customer informationclient.customers().list() - List all customersclient.customers().get_billing() - Get billing details for a customer# Run unit tests
cargo test
# Run integration tests (requires API key)
FLOWGLAD_API_KEY=sk_test_... cargo test --test integration_tests
For local development, create a .env file:
cp .env.example .env
# Edit .env and add your test API key
Integration tests will automatically load environment variables from .env if it exists.
The FlowGlad API uses your system's identifiers (external IDs) for most operations:
// Create with your ID
let customer = client.customers()
.create(CreateCustomer::new("user_123", "Jane"))
.await?;
// customer.id is FlowGlad's internal ID (e.g., "cus_abc")
// customer.external_id is your ID ("user_123")
// Use external_id for retrieval and updates
let customer = client.customers().get("user_123").await?;
All create and update operations use the builder pattern for ergonomic, self-documenting code:
CreateCustomer::new("required_id", "required_name")
.email("optional@example.com") // Optional fields
.phone("+1-555-0123") // chain naturally
.metadata("key", json!("value"));
Full API documentation is available at docs.rs/flowglad.
Build documentation locally:
cargo doc --open
Contributions are welcome! Please feel free to submit a Pull Request.
Before submitting:
# Run tests
cargo test --all-targets
# Check formatting
cargo fmt --check
# Run clippy
cargo clippy --all-targets --all-features
This project is licensed under the MIT License - see the LICENSE file for details.
Built for the FlowGlad open-source billing platform.