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.1.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.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: toktak_config_fetcher-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 0ab50e71b7bfef36502480d03a6bb822c70e68cebdc560f26a5a8ffbad0ccc69
MD5 c1a253cead30b6b1036841db15df0d37
BLAKE2b-256 f3283cfd3a6d2a4361a25d2c2ae1ebc882005280d5b0bf405dae265911d3b8ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toktak_config_fetcher-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ecd6dd5971d964242d3ca471dfa9e1e7d9efeca28a26952e03c49206ab785c21
MD5 87557aa7b3f78665f1300f4f21089181
BLAKE2b-256 b9bd105dfb7590d96ca0af42c06870648d291ed8e8f859688cad74d20f8d8186

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