Skip to main content

A simple config file loader that can read values from AWS.

Project description

Configgy

Configgy help you keep configuration files isomorphic. You can keep your configs entirely in your repo, loading secret values externally. Configs can be yaml or json, and can pull values from SSM, Secrets Manager, or S3. Fetched values can be strings or JSON.

Note: As a design decision, Configgy will never support default values or cascading/inherited configs. All configs should be straightforward to read and not increase cognitive load. This library is designed to fail fast and raise an exception, not continue with bad data.

Installation

pip install roadsync_configgy

or

poetry add roadsync_configgy

Example Use

Assuming:

project/
├── configs/
│   ├── local.yaml
│   └── deployed.yaml
└── main.py
# local.yaml
port: 3001
env: 'local'
api_key: 'fakeabc123'
users_table: 'AppName-Users'
documents_table: 'AppName-Documents'
service_host: 'locahost'
# deployed.yaml
port: 3001
env: 'ssm://env'    # dev|test|prod
api_key: 'secret://myservice/api_key'
users_table: 'AppName-Users'
documents_table: 'AppName-Documents'
service_host: 'ssm://myservice/host' # api.myservice.com
import os
from roadsync_configgy import load_config
from dataclasses import dataclass

@dataclass
class AppConfig:
    port: int
    env: str
    api_key: str
    users_table: str
    documents_table: str
    service_host: str

# Determine which environment we're running in
config_name = os.getenv('CONFIG')

# Load from path/to/config.yaml
config: AppConfig = load_config(f'configs/{config_name}.yaml')

http_serve(config.port)
# example usage
CONFIG='local' flask run

Supported Loading Types

secret://my-secret-key
ssm://my-ssm-parameter
s3://my-s3-bucket/my-file.txt
env://MY_ENV_VARIABLE

# parses the json
json+secret://my-secret-key
json+ssm://my-ssm-parameter
json+s3://my-s3-bucket/my-json-file.json
json+env://MY_ENV_VARIABLE

example config, showcasing all the loading types

# path/to/config.yaml

# Database settings using AWS Secrets Manager
db:
  host: 'db.services.local'
  username: "secret://db-username"  # Fetches username from Secrets Manager
  password: "secret://db-password"  # Fetches password from Secrets Manager

# AWS settings using AWS SSM
aws:
  region: "ssm://aws-region"            # Fetches AWS region from SSM
  instance_id: "ssm://aws-instance-id"  # Fetches AWS instance ID from SSM

# Application settings using Environment Variables
app:
  mode: "env://APP_MODE"  # Fetches app mode from environment variable APP_MODE
  port: "env://APP_PORT"  # Fetches app port from environment variable APP_PORT

# Feature toggles using JSON in Environment Variables
features:
  enabled: "json+env://ENABLED_FEATURES"  # Fetches JSON array from env var ENABLED_FEATURES

# Secrets in JSON format from AWS Secrets Manager
secrets:
  api_keys: "json+secret://api-keys"  # Fetches and parses JSON API keys from Secrets Manager

# AWS S3 files
files:
  config_file: "s3://my-bucket/config-file"  # Fetches config file from S3 bucket

# Data in JSON format from AWS S3
s3_data:
  important_data: "json+s3://my-bucket/important-data.json"  # Fetches and parses JSON from S3

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

roadsync_configgy-1.6.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

roadsync_configgy-1.6.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file roadsync_configgy-1.6.2.tar.gz.

File metadata

  • Download URL: roadsync_configgy-1.6.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/5.15.154+

File hashes

Hashes for roadsync_configgy-1.6.2.tar.gz
Algorithm Hash digest
SHA256 21b6280e512bd84ac1b6e05814495e0e3a8d779509f31c28c6279a785cb11396
MD5 a8deadbf4e3cc6fd66a103fffe05c0b3
BLAKE2b-256 33f00fd913896e55a5d4920bba4ae09aecfccf0c4277d415907033903f8f818f

See more details on using hashes here.

File details

Details for the file roadsync_configgy-1.6.2-py3-none-any.whl.

File metadata

  • Download URL: roadsync_configgy-1.6.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/5.15.154+

File hashes

Hashes for roadsync_configgy-1.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b6f41e17bf8a13ae993a5d74d0758180e2e8d1fc18b2642c9d33d0648d7b3fc8
MD5 dbeecec853746da7eff572410be0a6be
BLAKE2b-256 e4ceb0d4bfac25927bece831c8aedd74d46eb1dbeb9b0d60c1be58fe6135797d

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