Easily configure Python apps via environment variables, YAML, and AWS SSM Param Store.
Project description
Flex Config
Configure your applications as easily as possible.
Main Features
Load config from wherever
- Comes with built in support for loading from dicts, environment variables, JSON/YAML/TOML files, and AWS SSM Parameter Store.
- Super easy to set up a custom source and load from anywhere.
Type conversion, validation, and hints via Pydantic
# "ConfigSchema" is pydantic's BaseModel renamed and re-exported for easier use
from flex_config import ConfigSchema, construct_config
class Config(ConfigSchema):
a_string: str
an_int: int
# Raises ValidationError
my_bad_config = construct_config(Config, {"a_string": ["not", "a", "string"], "an_int": "seven"})
my_good_config = construct_config(Config, {"a_string": "my_string", "an_int": "7"})
assert isinstance(my_good_config.an_int, int)
Dynamic loading of config values
from pathlib import Path
from typing import Dict, Any
# "ConfigSchema" is pydantic's BaseModel renamed and re-exported for easier use
from flex_config import ConfigSchema, construct_config, AWSSource, YAMLSource, EnvSource, ConfigSource
class Config(ConfigSchema):
env: str
my_thing: str
def get_ssm_params(config_so_far: Dict[str, Any]) -> ConfigSource:
# env is set to live or dev via environment variables in the deployment environment
env = config_so_far.get("env")
if env == "local": # Not a live deployment, my_thing is in a local yaml file
return {}
return AWSSource(f"my_app/{config_so_far['env']}")
my_config = construct_config(Config, [EnvSource("MY_APP_"), YAMLSource(Path("my_file.yaml")), get_ssm_params])
Installation
Basic install: poetry install flex_config
With all optional dependencies (support for AWS SSM, YAML, and TOML): poetry install flex_config -E all
For a full tutorial and API docs, check out the hosted documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flex-config-2.2.0rc0.tar.gz
(10.0 kB
view details)
Built Distribution
File details
Details for the file flex-config-2.2.0rc0.tar.gz
.
File metadata
- Download URL: flex-config-2.2.0rc0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.8.15 Linux/5.15.0-1030-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ce47ffa0faa8118f9c501068d3702e080845c2740887f2e2d3f3a951dca8aff |
|
MD5 | 3556434a28d291ea1876acd2cb6eb291 |
|
BLAKE2b-256 | ef252d30fafdad4015d35afb428dfefc3d8e2bf9a0b80d29d2f4c3f23fcae5ed |
File details
Details for the file flex_config-2.2.0rc0-py3-none-any.whl
.
File metadata
- Download URL: flex_config-2.2.0rc0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.8.15 Linux/5.15.0-1030-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9571205339c4afea2b8df00952b0a3fbb430c1ed574c3d2d53d51af721c8be15 |
|
MD5 | 0610156a962aeb9040afac4fa96a1e08 |
|
BLAKE2b-256 | 0ed7c4c384b75d5309c6fadc171348d3e6acf5ba8cb557b30cb644bd2260e4db |