Skip to main content

Cache secrets locally from AWS Secrets Manager and other secret stores.

Project description

Secrets Cache

PyPI version Documentation Status

Cache secrets locally from AWS Secrets Manager and other secret stores, with optional local caching for development or Lambda-friendly usage.

Installation

Install the base package (minimal, Lambda-friendly):

pip install secrets-cache[lambda]

Install with local cache support (TOML) for testing / development:

pip install secrets-cache[local]

Install with CLI support:

pip install secrets-cache[cli]

You can also combine extras:

pip install "secrets-cache[local,cli]"

Usage

from secrets_cache import get_secret, get_param

# Get a secret from AWS Secrets Manager
my_secret = get_secret("my-secret-name", region="us-east-1")

# Get a parameter from AWS SSM Parameter Store
my_param = get_param("/my/parameter/name", region="us-east-1")

Notes:

  • By default, secrets are cached in memory to reduce repeated AWS calls.
  • If local extra is installed, secrets are also stored in ~/.secrets_cache.toml for local caching.
  • Module-level caches persist across warm AWS Lambda invocations, so repeated calls in the same container are very fast.

Features

  • Fetch secrets and parameters from AWS Secrets Manager / SSM.
  • Module-level caching for in-process efficiency.
  • Optional TOML caching for development.
  • Lambda-friendly usage without extra dependencies.
  • Easy to extend to other secret stores in the future.

Getting Started: AWS Lambda

When running in AWS Lambda, you usually don’t want file-based caching. Use the lambda extra:

pip install secrets-cache[lambda]

Example Lambda handler

import json
from secrets_cache import get_secret, get_param

def lambda_handler(event, context):
    # Get a secret from AWS Secrets Manager
    db_password = get_secret("my-db-password", region="us-east-1")

    # Get a parameter from AWS SSM Parameter Store
    api_key = get_param("/my/api/key", region="us-east-1")

    # Do something with your secrets
    return {
        "statusCode": 200,
        "body": json.dumps({
            "db_password_length": len(db_password),
            "api_key_length": len(api_key)
        })
    }

Notes for Lambda

  • Module-level caching ensures repeated calls in the same container are very fast.
  • No TOML or local file access is required — perfect for ephemeral Lambda environments.
  • Secrets are cached in memory only, and each new container start fetches them from AWS.
  • If you want local development caching, install the local extra:
pip install secrets-cache[local]

This enables optional ~/.secrets_cache.toml caching for local testing.

Credits

Created with Cookiecutter and the rnag/cookiecutter-pypackage template.

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

secrets_cache-0.2.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

secrets_cache-0.2.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file secrets_cache-0.2.0.tar.gz.

File metadata

  • Download URL: secrets_cache-0.2.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for secrets_cache-0.2.0.tar.gz
Algorithm Hash digest
SHA256 86c39b33b24c0f67e7b9fbaeddd368849e994a6f8a1860e5f5a8f2907f1c138f
MD5 abefbc28033a56b8a67458c325868530
BLAKE2b-256 e1978de8e6922226b4b23b4b801dfc1ec90c4d5495129cb2ade22b71fe4a2ab9

See more details on using hashes here.

File details

Details for the file secrets_cache-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: secrets_cache-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for secrets_cache-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61aba3a94a2d9540d6a58bdae6c6a60f2b212ef6b59ae90c8d0b523936ab66c8
MD5 86ef86fecdb7a95659a7b0979204c40d
BLAKE2b-256 612ddf03edff386dc0de6e0d91d2f4f0a055b288cce19c8bb8187be0f25d0ce5

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