Skip to main content

Helper package for using AWS App Config with Pydantic

Project description

https://badge.fury.io/py/pydantic-appconfig.svg https://img.shields.io/pypi/pyversions/pydantic-appconfig https://app.codacy.com/project/badge/Grade/7394b3a36fca46b38df857c415b3da3d https://app.codacy.com/project/badge/Coverage/7394b3a36fca46b38df857c415b3da3d

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

pip install pydantic-appconfig

With a lot of inspiration from this AWS sample.

Introducing pydantic_appconfig.

  1. Set yourself up with your favourite pydantic.BaseModel:

    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"
  2. Set up the config helper using your shiny config class:

    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,
    )
  3. Use it:

    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:

print(MyAppConfig.schema_json(indent=2))
{
  "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"
  ]
}

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

pydantic_appconfig-2.0.0.tar.gz (8.6 kB view hashes)

Uploaded Source

Built Distribution

pydantic_appconfig-2.0.0-py3-none-any.whl (9.2 kB view hashes)

Uploaded Python 3

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