Git Product home page Git Product logo

aws-appconfig-pydantic's Introduction

Pydantic AWS AppConfig

image

image

image

image

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"
  ]
}

aws-appconfig-pydantic's People

Contributors

fergusdixon avatar isaacmf1 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.