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.0.tar.gz (8.1 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.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: toktak_config_fetcher-1.0.0.tar.gz
  • Upload date:
  • Size: 8.1 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.0.tar.gz
Algorithm Hash digest
SHA256 d9e9dd5a0dd28936b44180a22ff38a8bb73de2c89a1d6b54a29116c1a5c6ff7e
MD5 beaad0d6a7008706ce936dae27a735b8
BLAKE2b-256 d6c590501f16ceca4ea5a3c18656559a345cf5ec5da0adf922b3b010629fef29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toktak_config_fetcher-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c552208e8ca4501312827d92bce1969c2349369eba51e961f51862881554206
MD5 8cc235414b4bf78256a187e10c8e0b8e
BLAKE2b-256 df651919631bc94808f93541f09301af70edfb6668fb55de247384ad4a8f08f7

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