Skip to main content

CubeSDK: Secure secret management client

Project description

CubeSDK

Python SDK for Cube secret management with built-in caching, environment switching, and automatic error handling. Website: https://usecube.co

Features

  • 🔐 Secure Secret Management - Retrieve secrets from Cube with service token authentication
  • Built-in Caching - TTL-based caching to reduce API calls and improve performance
  • 🌍 Environment Support - Switch between environments (development, staging, production) seamlessly
  • 🔄 Auto-refresh - Automatic cache invalidation and refresh capabilities
  • 🛡️ Error Handling - Comprehensive exception handling for authentication, authorization, and API errors
  • 📦 Simple API - Clean and intuitive interface for secret management

Installation

Install CubeSDK using pip:

pip install cubesdk

Quick Start

from cubesdk import CubeSDK

# Initialize client with a service token and default environment
client = CubeSDK(
    service_token="st_dev_xxx",
    default_env="development",
    cache_ttl=120,  # Cache secrets for 2 minutes
)

# Get a single secret
db_password = client.get_secret("DB_PASSWORD")

# Get all secrets
secrets = client.get_secrets()

# Switch environment
client.switch_env("staging")
api_key = client.get_secret("API_KEY")

# Force refresh cache
client.refresh()

Configuration

The CubeSDK client accepts the following parameters:

  • service_token (str, required): Your Cube service token for authentication
  • api_version (str, optional): API version to use (defaults to environment variable or configured value)
  • default_env (str, optional): Default environment name (default: "development")
  • base_url (str, optional): Base URL for the Cube API (defaults to environment variable or configured value)
  • timeout (int, optional): Request timeout in seconds (default: 5)
  • cache_ttl (int, optional): Cache time-to-live in seconds (default: 60)

API Reference

get_secret(key: str) -> str

Retrieve a single secret by key. The secret is cached based on the current environment and cache TTL.

password = client.get_secret("DB_PASSWORD")

get_secrets() -> Dict[str, str]

Retrieve all secrets for the current environment. All secrets are cached automatically.

all_secrets = client.get_secrets()
# Returns: {"DB_PASSWORD": "secret123", "API_KEY": "key456", ...}

switch_env(environment: str)

Switch to a different environment. This clears the cache to ensure fresh secrets are fetched.

client.switch_env("staging")

refresh()

Force refresh all cached secrets by clearing the cache.

client.refresh()

Error Handling

The SDK provides specific exception types for different error scenarios:

from cubesdk import CubeSDK
from cubesdk.exceptions import (
    AuthenticationError,
    AuthorizationError,
    SecretNotFoundError,
    APIError,
)

try:
    secret = client.get_secret("MY_SECRET")
except AuthenticationError:
    print("Invalid or expired service token")
except AuthorizationError:
    print("Access denied for this environment")
except SecretNotFoundError:
    print("Secret not found in the current environment")
except APIError as e:
    print(f"API error: {e}")

Examples

Basic Usage

from cubesdk import CubeSDK

client = CubeSDK(
    service_token="st_dev_xxx",
    default_env="development",
    cache_ttl=300,  # 5 minutes
)

# Get secrets
db_host = client.get_secret("DB_HOST")
db_password = client.get_secret("DB_PASSWORD")
api_key = client.get_secret("API_KEY")

Environment Switching

# Start with development
client = CubeSDK(
    service_token="st_dev_xxx",
    default_env="development",
)

prod_secret = client.get_secret("SECRET_KEY")

# Switch to staging
client.switch_env("staging")
staging_secret = client.get_secret("SECRET_KEY")

Batch Secret Retrieval

# Get all secrets at once (more efficient for multiple secrets)
secrets = client.get_secrets()
db_config = {
    "host": secrets["DB_HOST"],
    "port": secrets["DB_PORT"],
    "password": secrets["DB_PASSWORD"],
}

Custom Configuration

client = CubeSDK(
    service_token="st_dev_xxx",
    default_env="development",
    base_url="https://api.cube.example.com",
    timeout=10,
    cache_ttl=600,  # 10 minutes
    api_version="v1",
)

Requirements

  • Python 3.9+
  • requests>=2.31.0

License

MIT

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

cubesdk-0.1.3.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

cubesdk-0.1.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file cubesdk-0.1.3.tar.gz.

File metadata

  • Download URL: cubesdk-0.1.3.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for cubesdk-0.1.3.tar.gz
Algorithm Hash digest
SHA256 03673e339c1832de0ac6294b583797a27f25e92e5ca80957f5f6d14de2227371
MD5 8075d39353c222b068b8e22f6c88c2a9
BLAKE2b-256 ee5e45896a7df1f1bd4b76cc7ff9647b7fc9f5bf999690e1204fe506d898d059

See more details on using hashes here.

File details

Details for the file cubesdk-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: cubesdk-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for cubesdk-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 281bf83eb586e13adec3683273612a734ca13adba6e882f8631bc1a8d12ff785
MD5 69b8ef4fa46f36ab4068cb552ca44640
BLAKE2b-256 dba79015fe308120eb17480dfdeb1c3d933f2888259a583c68ac481dc6264a39

See more details on using hashes here.

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