Skip to main content

Config utility library to fetch configuration from AWS SSM/Secrets Manager and .env files

Project description

Toktak Config Fetcher

Description

A Python utility library for loading configuration from AWS Systems Manager (SSM) Parameter Store, AWS Secrets Manager, and .env files. Provides a unified interface with caching and TTL support.

Installation

From PyPI

pip install toktak-config-fetcher

From source

git clone <repository-url>
cd toktak_config_fetcher
pip install .

Usage

from toktak_config_fetcher import preload_config, get_config, get_config_int

# Preload all config from .env and AWS (optional)
preload_config()  # Loads all keys from .env file

# Or preload specific keys
preload_config(["DATABASE_URL", "PORT", "API_KEY"])

# Get string config (fetches from AWS if not cached, falls back to .env)
database_url = get_config("DATABASE_URL", default_value="sqlite:///default.db")

# Get integer config
port = get_config_int("PORT", default_value=8080)

Logic Flow

  1. Load all config from .env file.
  2. Fetch values from AWS for the keys found in .env file (if not in local mode).
  3. The values from AWS are stored in a cache.
  4. The cache has a TTL (Time to Live) of 300 seconds. If the TTL expires, values will be fetched from AWS again.
  5. The secret key must start with SECRET_ prefix.
  6. In local mode (DEPLOY_ENV=local), only .env file values are used.
  7. In non-local mode, AWS values take priority over .env file values.

Environment Variables

Required Configuration

  1. REGION: The AWS Region. Default value is ap-northeast-2
  2. ORG: Organization name. Default value is vodaplay
  3. DEPLOY_ENV: The AWS Environment. Possible values: local, dev, stg, prod. Default is local
  4. APP_NAMESPACE: The group/namespace of this project. The config utils will combine ORG, DEPLOY_ENV, and APP_NAMESPACE to form the prefix for env key when getting config value from AWS

AWS Configuration

Ensure your AWS credentials are configured via:

  • AWS credentials file (~/.aws/credentials)
  • Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  • IAM role (when running on EC2/ECS/Lambda)

AWS Path Structure

  • SSM Parameters: /{ORG}/{DEPLOY_ENV}/{APP_NAMESPACE}/{key} or /{ORG}/{DEPLOY_ENV}/COMMON/{key}
  • Secrets: /{ORG}/{DEPLOY_ENV}/{SECRET_key}

Development

# Install with development dependencies
pip install -e ".[dev,test,linting]"

# Run tests
pytest

# Run linting
flake8 toktak_config_fetcher

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

toktak_config_fetcher-1.0.2.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

toktak_config_fetcher-1.0.2-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file toktak_config_fetcher-1.0.2.tar.gz.

File metadata

  • Download URL: toktak_config_fetcher-1.0.2.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for toktak_config_fetcher-1.0.2.tar.gz
Algorithm Hash digest
SHA256 4561a925307a6b203e992ed2383e30e6595120d85e240aec431daf5c29da1fc6
MD5 9913761d6ee1b9e4a3c787beeb7cb49e
BLAKE2b-256 db9aead0d70e33266cf58fab0ef7ac12ada2256b06f0e68ccd9e83c0061985b8

See more details on using hashes here.

File details

Details for the file toktak_config_fetcher-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for toktak_config_fetcher-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e0e5ed0d0ef9995725f1cfb7fb2615f8581f5eb3d83679a9d7582abe7e74bfce
MD5 7c630e1f3b7c1a066bfb41cf13ad3448
BLAKE2b-256 d4d04083e04e4ecaf84b16234c54756beb028cd302856584f211ab56c914089d

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