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.5.0.tar.gz (3.9 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.5.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for roadsync_configgy-1.5.0.tar.gz
Algorithm Hash digest
SHA256 7d5eb1cdb9f16a0c70d12ec8e2d321957acc7020c81517802a342a90528394aa
MD5 c8f830a586ef41684f9a276306542afb
BLAKE2b-256 5013e1e386f5ef9f7f8dcc3ac87923ab383c71ce6644e3405a79f136b49eb0b0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for roadsync_configgy-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13a6afed5b14c9f1859a4810080ea072aabb13026e38db65906d8a51c110c700
MD5 84b564a878947447acba5db18dea8400
BLAKE2b-256 fbcf31cf53515137696571dc218095361daf477e8f5890c4569bfa44f80594e9

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