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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file roadsync_configgy-1.4.2.tar.gz.
File metadata
- Download URL: roadsync_configgy-1.4.2.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/5.4.109+
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdfb55047e4def9354b0884a8ea0b4ef3f315ace32bfdcb1e16cc218c4933995
|
|
| MD5 |
52436e16569ef833134b231f4a61df9a
|
|
| BLAKE2b-256 |
1b7f23edced4c05062bee85ad84b1697ab05181c16c2ccdafda225a7fb2d3d6d
|
File details
Details for the file roadsync_configgy-1.4.2-py3-none-any.whl.
File metadata
- Download URL: roadsync_configgy-1.4.2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
687d2ca1493be3556d28563d72760fb1e61efad4b4ab626c150d0859bd537be4
|
|
| MD5 |
99aea27780888f3fee7001fab90d6672
|
|
| BLAKE2b-256 |
30e9c3bf52bd5575e71b6d9a0a2146b58edf2c7e6f1d5caabb5f94c1cb1bb88d
|