# Flex Config
[![codecov](https://codecov.io/gh/triaxtec/flex-config/branch/master/graph/badge.svg?token=3utvPfZSLB)](https://codecov.io/gh/triaxtec/flex-config)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Generic badge](https://img.shields.io/badge/type_checked-mypy-informational.svg)](https://mypy.readthedocs.io/en/stable/introduction.html)
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)
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]
```python
# "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
```python
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]
[Pydantic]: https://github.com/samuelcolvin/pydantic/
[hosted documentation]: https://triaxtec.github.io/flex-config
Raw data
{
"_id": null,
"home_page": "https://github.com/emann/flex-config",
"name": "flex-config",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<4.0",
"maintainer_email": "",
"keywords": "config,AWS,SSM,serverless,environment",
"author": "Dylan Anthony",
"author_email": "danthony@triaxtec.com",
"download_url": "https://files.pythonhosted.org/packages/1d/75/1d5c28ab66844e3274cb89f84e4b3890a6dc946ca1510a23e8bc9bbcdd65/flex_config-3.0.0.tar.gz",
"platform": null,
"description": "# Flex Config\n[![codecov](https://codecov.io/gh/triaxtec/flex-config/branch/master/graph/badge.svg?token=3utvPfZSLB)](https://codecov.io/gh/triaxtec/flex-config)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Generic badge](https://img.shields.io/badge/type_checked-mypy-informational.svg)](https://mypy.readthedocs.io/en/stable/introduction.html)\n[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)\n\n\nConfigure your applications as easily as possible.\n\n## Main Features\n### Load config from wherever\n- Comes with built in support for loading from dicts, environment variables, JSON/YAML/TOML files, and AWS SSM Parameter Store.\n- Super easy to set up a custom source and load from anywhere.\n\n### Type conversion, validation, and hints via [Pydantic]\n```python\n# \"ConfigSchema\" is pydantic's BaseModel renamed and re-exported for easier use \nfrom flex_config import ConfigSchema, construct_config\n\nclass Config(ConfigSchema):\n a_string: str\n an_int: int\n\n# Raises ValidationError\nmy_bad_config = construct_config(Config, {\"a_string\": [\"not\", \"a\", \"string\"], \"an_int\": \"seven\"})\n\nmy_good_config = construct_config(Config, {\"a_string\": \"my_string\", \"an_int\": \"7\"})\nassert isinstance(my_good_config.an_int, int)\n```\n\n### Dynamic loading of config values\n```python\nfrom pathlib import Path\nfrom typing import Dict, Any\n\n# \"ConfigSchema\" is pydantic's BaseModel renamed and re-exported for easier use \nfrom flex_config import ConfigSchema, construct_config, AWSSource, YAMLSource, EnvSource, ConfigSource\n\nclass Config(ConfigSchema):\n env: str\n my_thing: str\n\ndef get_ssm_params(config_so_far: Dict[str, Any]) -> ConfigSource:\n # env is set to live or dev via environment variables in the deployment environment\n env = config_so_far.get(\"env\")\n if env == \"local\": # Not a live deployment, my_thing is in a local yaml file\n return {}\n return AWSSource(f\"my_app/{config_so_far['env']}\")\n\n\nmy_config = construct_config(Config, [EnvSource(\"MY_APP_\"), YAMLSource(Path(\"my_file.yaml\")), get_ssm_params])\n```\n\n## Installation\nBasic install: `poetry install flex_config`\nWith all optional dependencies (support for AWS SSM, YAML, and TOML): `poetry install flex_config -E all`\n\nFor a full tutorial and API docs, check out the [hosted documentation]\n\n[Pydantic]: https://github.com/samuelcolvin/pydantic/\n[hosted documentation]: https://triaxtec.github.io/flex-config\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Easily configure Python apps via environment variables, YAML, and AWS SSM Param Store.",
"version": "3.0.0",
"project_urls": {
"Documentation": "https://emann.github.io/flex-config",
"Homepage": "https://github.com/emann/flex-config",
"Repository": "https://github.com/emann/flex-config"
},
"split_keywords": [
"config",
"aws",
"ssm",
"serverless",
"environment"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e22d08b382d3859c85f42b72b5ce137ab19e2ac11e2d6efba8efa3c3e386dfd8",
"md5": "5dc1f5f39a9c676b093034136b2ae87f",
"sha256": "750920336e05c54b386098012c986b082fd3727fc9a3ef285de594125fb246cf"
},
"downloads": -1,
"filename": "flex_config-3.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5dc1f5f39a9c676b093034136b2ae87f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<4.0",
"size": 11149,
"upload_time": "2024-01-26T15:18:29",
"upload_time_iso_8601": "2024-01-26T15:18:29.433223Z",
"url": "https://files.pythonhosted.org/packages/e2/2d/08b382d3859c85f42b72b5ce137ab19e2ac11e2d6efba8efa3c3e386dfd8/flex_config-3.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1d751d5c28ab66844e3274cb89f84e4b3890a6dc946ca1510a23e8bc9bbcdd65",
"md5": "55a867cad2c492890907a1a3088970c2",
"sha256": "032a059b90f793a6647948fd58169ef3ccb012324ba5cef4ce457aa3dbf26849"
},
"downloads": -1,
"filename": "flex_config-3.0.0.tar.gz",
"has_sig": false,
"md5_digest": "55a867cad2c492890907a1a3088970c2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<4.0",
"size": 8013,
"upload_time": "2024-01-26T15:18:30",
"upload_time_iso_8601": "2024-01-26T15:18:30.541192Z",
"url": "https://files.pythonhosted.org/packages/1d/75/1d5c28ab66844e3274cb89f84e4b3890a6dc946ca1510a23e8bc9bbcdd65/flex_config-3.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-26 15:18:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "emann",
"github_project": "flex-config",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "flex-config"
}