Skip to content

Quickstart

import boto3
from cps_vault_sdk import SecretNotFoundError, VaultSDK

sdk = VaultSDK(aws_profile="my-profile")

secret_name = "my-app/db-password"

# Create — encrypted locally before it's ever sent over the network.
sdk.create(
    secret_name, "s3cr3t!",
    application_name="my-app", ttl="6h", cps_project_name="cps-project-1",
    description="Primary DB password for my-app",  # optional
)

# Fetch — retrieves and decrypts in one call.
print(sdk.fetch(secret_name))  # "s3cr3t!"

# Update — replaces the value and refreshes tags.
sdk.put(secret_name, "n3w-s3cr3t!", ttl="6h", cps_project_name="cps-project-1")

# List — catalog metadata only, no decryption.
print(sdk.list_secrets())
# {"secrets": [{"name": "...", "description": "...", "last_changed": "..."}, ...], "count": 1}

try:
    sdk.fetch("does-not-exist")
except SecretNotFoundError as e:
    print(f"not found: {e}")

A few things worth knowing:

  • aws_profile is optional — omit it to fall back to the default AWS credential chain (environment variables, instance/task role, SSO, etc.).
  • plaintext may be a str or a JSON-serializable dict. fetch() always returns a str; use json.loads(...) yourself if you stored a dict.
  • ttl is a short-hand duration ("10m", "6h", "30d", "2w", "3mo", "1y") — not a calendar date.
  • create() transparently falls back to updating the secret if it already exists, so a plain create-or-update flow doesn't need to branch on that case.

See User Guide for the full method reference, and Configuration for every constructor option.