Skip to main content

Easily configure Python apps via environment variables, YAML, and AWS SSM Param Store.

Project description

Flex Config

codecov Code style: black Generic badge MIT license

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


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.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

flex_config-2.2.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file flex_config-2.2.1.tar.gz.

File metadata

  • Download URL: flex_config-2.2.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.8.17 Linux/5.15.0-1041-azure

File hashes

Hashes for flex_config-2.2.1.tar.gz
Algorithm Hash digest
SHA256 0d2086d33588cdc99e32c2974efb0f203fa743674ab5efcd684641b7445530a4
MD5 5902580adf23095f04458c1a285a2b33
BLAKE2b-256 5cb19cec7eb775e1094fca5f53c27a33318a3a6cb9966520c2d8b1d9ff52a54e

See more details on using hashes here.

File details

Details for the file flex_config-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: flex_config-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.8.17 Linux/5.15.0-1041-azure

File hashes

Hashes for flex_config-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b85cd1fa4a43930c90d424a907542a24dac6106f069341dc29a3bc62de80524b
MD5 c03327989207d577b6d37061393f43dc
BLAKE2b-256 f445f5fcf7949146521e9207fd1116e729aa88367e1fd35cac88913900ab64e6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page