Skip to main content

Python bindings for Redis Cloud REST API client

Project description

redis-cloud

Crates.io Documentation CI License PyPI

A comprehensive Rust client library for the Redis Cloud REST API, with Python bindings.

Features

  • Complete coverage of Redis Cloud REST API endpoints
  • Async/await support with tokio
  • Strong typing for API requests and responses
  • Comprehensive error handling
  • Optional Tower service integration for middleware composition
  • Support for all Redis Cloud features including:
    • Pro and Essentials subscriptions and databases
    • User and ACL management
    • Backup, restore, and import operations
    • VPC peering, Transit Gateway, Private Service Connect, PrivateLink
    • Cloud account integration (AWS, GCP, Azure)
    • Task tracking for async operations
    • Cost reports (FOCUS format)

Installation

[dependencies]
redis-cloud = "0.8"

# Optional: Enable Tower service integration
redis-cloud = { version = "0.8", features = ["tower-integration"] }

Quick Start

use redis_cloud::CloudClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create client using builder pattern
    let client = CloudClient::builder()
        .api_key("your-api-key")
        .api_secret("your-api-secret")
        .build()?;

    // Get account information using fluent API
    let account = client.account().get_current_account().await?;
    println!("Account: {:?}", account);

    // List all subscriptions
    let subscriptions = client.subscriptions().get_all_subscriptions().await?;
    println!("Subscriptions: {:?}", subscriptions);

    // List databases in a subscription
    let databases = client.databases().get_subscription_databases(123, None, None).await?;
    println!("Databases: {:?}", databases);

    Ok(())
}

You can also use explicit handler creation if preferred:

use redis_cloud::{CloudClient, SubscriptionHandler};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = CloudClient::builder()
        .api_key("your-api-key")
        .api_secret("your-api-secret")
        .build()?;

    // Explicit handler creation
    let handler = SubscriptionHandler::new(client.clone());
    let subscriptions = handler.get_all_subscriptions().await?;

    Ok(())
}

Tower Integration

Enable the tower-integration feature to use the client with Tower middleware:

use redis_cloud::CloudClient;
use redis_cloud::tower_support::ApiRequest;
use tower::ServiceExt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = CloudClient::builder()
        .api_key("your-api-key")
        .api_secret("your-api-secret")
        .build()?;

    // Convert to a Tower service
    let mut service = client.into_service();

    // Use the service
    let response = service
        .oneshot(ApiRequest::get("/subscriptions"))
        .await?;

    println!("Response: {:?}", response.body);
    Ok(())
}

This enables composition with Tower middleware like circuit breakers, retry, rate limiting, and more.

Examples

See the examples/ directory for runnable examples:

# Basic usage - connect and list subscriptions
REDIS_CLOUD_API_KEY=xxx REDIS_CLOUD_API_SECRET=yyy cargo run --example basic

# Database operations
REDIS_CLOUD_API_KEY=xxx REDIS_CLOUD_API_SECRET=yyy cargo run --example databases

# Streaming with pagination
REDIS_CLOUD_API_KEY=xxx REDIS_CLOUD_API_SECRET=yyy cargo run --example stream_databases -- SUBSCRIPTION_ID

Python Bindings

This library also provides Python bindings via PyO3:

pip install redis-cloud
from redis_cloud import CloudClient

# Create client
client = CloudClient(
    api_key="your-api-key",
    api_secret="your-api-secret"
)

# Or from environment variables
client = CloudClient.from_env()

# Async usage
async def main():
    subs = await client.subscriptions()
    for sub in subs:
        print(sub["name"], sub["id"])

# Sync usage
subs = client.subscriptions_sync()

Python API

  • CloudClient(api_key, api_secret, base_url=None, timeout_secs=None)
  • CloudClient.from_env() - Create from environment variables
  • client.timeout - Get configured timeout in seconds (property)

Account

  • account() / account_sync() - Get current account information

Subscriptions

  • subscriptions() / subscriptions_sync() - List all subscriptions
  • subscription(id) / subscription_sync(id) - Get subscription by ID

Databases

  • databases(subscription_id, offset=None, limit=None) / databases_sync(...) - List databases (paginated)
  • database(subscription_id, database_id) / database_sync(...) - Get database
  • all_databases(subscription_id) / all_databases_sync(...) - Get all databases (auto-pagination)

Raw API

  • get(path) / get_sync(path) - Raw GET request
  • post(path, body) / post_sync(path, body) - Raw POST request
  • delete(path) / delete_sync(path) - Raw DELETE request

Environment Variables

  • REDIS_CLOUD_API_KEY - API key
  • REDIS_CLOUD_API_SECRET - API secret
  • REDIS_CLOUD_BASE_URL - Base URL (optional)

API Coverage

This library provides comprehensive coverage of the Redis Cloud REST API:

Handler Description
account() Account info, payment methods, regions, logs
subscriptions() Pro subscription CRUD, pricing, CIDR, maintenance windows
databases() Pro database lifecycle, backups, imports, flush
fixed_subscriptions() Essentials subscription management
fixed_databases() Essentials database management
acl() ACL users, roles, Redis rules
users() Account user management
cloud_accounts() Cloud provider integration (AWS, GCP, Azure)
vpc_peering() VPC peering (standard and Active-Active)
transit_gateway() AWS Transit Gateway attachments
psc() GCP Private Service Connect
private_link() AWS PrivateLink
tasks() Async operation tracking
cost_reports() Cost reports in FOCUS format

Documentation

License

Licensed under either of

at your option.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redis_cloud-0.9.3.tar.gz (187.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

redis_cloud-0.9.3-cp312-cp312-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.12Windows x86-64

redis_cloud-0.9.3-cp312-cp312-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

redis_cloud-0.9.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file redis_cloud-0.9.3.tar.gz.

File metadata

  • Download URL: redis_cloud-0.9.3.tar.gz
  • Upload date:
  • Size: 187.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for redis_cloud-0.9.3.tar.gz
Algorithm Hash digest
SHA256 5050365b7cc79c8e13ce4e0725296ceaa719f270cb805041c91ce5e51c53089b
MD5 b064b23732d35d8990f036ba19211071
BLAKE2b-256 c8a502a59032069398af36e98532c5c563afc7f69ca1f7cac4ba2caa02bb9f04

See more details on using hashes here.

Provenance

The following attestation bundles were made for redis_cloud-0.9.3.tar.gz:

Publisher: python.yml on redis-developer/redis-cloud-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redis_cloud-0.9.3-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for redis_cloud-0.9.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 66d1fef314d47bbbe76294ae49d94f5948e80b01db6f78005e92fc14ee3efcc1
MD5 6212e381e3090e0a916ed46037efb718
BLAKE2b-256 52e9b4b87d70cd92d7868012811e57a93188c87c965e9364012b695ba8638afd

See more details on using hashes here.

Provenance

The following attestation bundles were made for redis_cloud-0.9.3-cp312-cp312-win_amd64.whl:

Publisher: python.yml on redis-developer/redis-cloud-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redis_cloud-0.9.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for redis_cloud-0.9.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 48121a10ca5f77b2fef8c76da1d41d81cf674df3dc253c5454aa98713e1940c4
MD5 ce615d4063de647e9dbe540b0d12a106
BLAKE2b-256 91eb553015ac39f264eabfe3cd962a556b5df06c64354ba305d2aa0a32f37b51

See more details on using hashes here.

Provenance

The following attestation bundles were made for redis_cloud-0.9.3-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: python.yml on redis-developer/redis-cloud-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redis_cloud-0.9.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redis_cloud-0.9.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a4cb7f1526cf1ef49f0f53c9445de1e3af29f85d306983375ed1e9793194282e
MD5 0440c4be2234b7774acad84ba78a70bd
BLAKE2b-256 53dcde642c77734567987b02bfb21b6b6b1b9066ee8da5ffb5fe56a531aeee8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for redis_cloud-0.9.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python.yml on redis-developer/redis-cloud-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page