https://github.com/validus-risk-management/aws-appconfig-pydantic
AWS AppConfig + Pydantic
https://github.com/validus-risk-management/aws-appconfig-pydantic
appconfig aws config pydantic python3
Last synced: 12 months ago
JSON representation
AWS AppConfig + Pydantic
- Host: GitHub
- URL: https://github.com/validus-risk-management/aws-appconfig-pydantic
- Owner: Validus-Risk-Management
- License: apache-2.0
- Created: 2021-09-23T14:21:07.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-07-24T09:52:27.000Z (almost 3 years ago)
- Last Synced: 2025-05-13T16:37:39.709Z (about 1 year ago)
- Topics: appconfig, aws, config, pydantic, python3
- Language: Python
- Homepage:
- Size: 112 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Pydantic AWS AppConfig
=======================
.. image:: https://badge.fury.io/py/pydantic-appconfig.svg
:target: https://badge.fury.io/py/pydantic-appconfig
.. image:: https://img.shields.io/pypi/pyversions/pydantic-appconfig
:target: https://img.shields.io/pypi/pyversions/pydantic-appconfig
.. image:: https://app.codacy.com/project/badge/Grade/7394b3a36fca46b38df857c415b3da3d
:target: https://www.codacy.com/gh/Validus-Risk-Management/aws-appconfig-pydantic/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Validus-Risk-Management/aws-appconfig-pydantic&utm_campaign=Badge_Grade
.. image:: https://app.codacy.com/project/badge/Coverage/7394b3a36fca46b38df857c415b3da3d
:target: https://www.codacy.com/gh/Validus-Risk-Management/aws-appconfig-pydantic/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Validus-Risk-Management/aws-appconfig-pydantic&utm_campaign=Badge_Coverage
Ever wanted to use
`AWS AppConfig `_
for your Python app, but can't bear configs without
`pydantic `_?
Well, your days of using evil `.env` or `.ini` files, `ENVIRONMENT` variables or even custom providers is over!
With just a simple
.. code-block:: shell
pip install pydantic-appconfig
With a lot of inspiration from this AWS `sample `_.
Introducing `pydantic_appconfig`.
#. Set yourself up with your favourite `pydantic.BaseModel`:
.. code-block:: python
class MyAppConfig(pydantic.BaseModel):
"""My app config."""
test_field_string: str
test_field_int: int
class Config:
"""The pydantic config, including title for the JSON schema."""
title = "MyAppConfig"
#. Set up the config helper using your shiny config class:
.. code-block:: python
from pydantic_appconfig import AppConfigHelper
my_config: AppConfigHelper[MyAppConfig] = AppConfigHelper(
appconfig_application="AppConfig-App",
appconfig_environment="AppConfig-Env",
appconfig_profile="AppConfig-Profile",
max_config_age=15,
fetch_on_init=True,
config_schema_model=MyAppConfig,
)
#. Use it:
.. code-block:: python
my_val = my_config.config.test_field_string
AWS AppConfig also has support for `validators `_.
Pydantic is able to generate a JSON schema for you to upload:
.. code-block:: python
print(MyAppConfig.schema_json(indent=2))
.. code-block:: JSON
{
"title": "MyAppConfig",
"description": "My app config.",
"type": "object",
"properties": {
"test_field_string": {
"title": "Test Field String",
"type": "string"
},
"test_field_int": {
"title": "Test Field Int",
"type": "integer"
}
},
"required": [
"test_field_string",
"test_field_int"
]
}