tencent-sdk 0.1.3

📦 Tencent Cloud API SDK written in Rust
Documentation

This project is a Tencent Cloud API SDK written in Rust, designed to help developers integrate Tencent Cloud services easily. The SDK uses asynchronous programming (via Tokio) and encapsulates functionalities such as request signing ( TC3-HMAC-SHA256), unified request handling, and modular service interfaces (e.g., CVM, Billing, Tag, etc.).

Usage

Add the crate

[dependencies]
tencent-sdk = "0.1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

Configure credentials and create clients

use tencent_sdk::{
    client::TencentCloudAsync,
    core::{TencentCloudError, TencentCloudResult},
    services::{
        cvm::{DescribeInstances, DescribeInstancesResponse},
        Filter,
    },
};

async fn describe_instances() -> TencentCloudResult<DescribeInstancesResponse> {
    let secret_id = std::env::var("TENCENT_SECRET_ID").expect("missing TENCENT_SECRET_ID");
    let secret_key = std::env::var("TENCENT_SECRET_KEY").expect("missing TENCENT_SECRET_KEY");

    let client = TencentCloudAsync::builder(secret_id, secret_key)?
        .no_system_proxy() // optional convenience helper
        .with_default_region("ap-guangzhou")
        .with_retry(3, std::time::Duration::from_millis(200))
        .build()?;

    let request = DescribeInstances::new()
        .with_region("ap-guangzhou")
        .with_limit(20)
        .push_filter(Filter::new("instance-name", ["example"]));

    client.request(&request).await
}

#[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<(), TencentCloudError> {
    let response = describe_instances().await?;
    println!("instances: {:?}", response.response.total_count);
    Ok(())
}

The blocking client mirrors the async API:

use tencent_sdk::{
    client::TencentCloudBlocking,
    services::billing::describe_account_balance_blocking,
};

fn fetch_balance() -> tencent_sdk::core::TencentCloudResult<()> {
    let client = TencentCloudBlocking::builder("secret", "key")?
        .no_system_proxy()
        .with_default_region("ap-guangzhou")
        .build()?;

    let result = describe_account_balance_blocking(&client)?;
    println!("balance: {:?}", result.response.real_balance);
    Ok(())
}

Features

  • Asynchronous & Blocking Clients: Tokio-powered async client plus a reqwest blocking client sharing configuration and retry middleware.
  • TC3 Signing Utilities: Reusable helpers to construct compliant TC3-HMAC-SHA256 headers.
  • Strongly Typed Services: Service modules expose typed request/response models and ergonomic builders for filters, tags, and pagination.
  • Actionable Error Taxonomy: Service errors are classified (auth, throttled, forbidden, etc.) via ServiceErrorKind for easier recovery logic.
  • Expanded Test Coverage: Wiremock-backed integration flows and deterministic signing snapshots keep regressions in check.

Implemented Interfaces

  • CVM Module

    • DescribeInstances
    • ResetInstancesPassword
    • DescribeInstanceVncUrl
    • StartInstances
    • RebootInstances
    • StopInstances
    • ModifyInstancesProject
  • Tag Module

    • DescribeProjects
  • Billing Module

    • DescribeAccountBalance