Skip to main content

Yaml support for Pydantic settings

Project description

pydantic-settings-yaml

Yaml support for Pydantic settings. Load a yaml config file as nested Pydantic models.

Allows to use file:xxxx placeholders in the yaml config file for secrets. A placeholder is replaced with the contents of the file. Paths are relative to the 'secrets_dir' setting (see below).

Usage

$cat /config/config.yaml

database: 
  password: <file:database_password>
  username: my_database_username

$cat /secrets/database_password

my_secret_database_password

Python code example:

    from pydantic import BaseModel
    from pydantic_settings_yaml import YamlBaseSettings

    class Database(BaseModel):
        username: str
        password: str


    class Settings(YamlBaseSettings):
        database: Database

        class Config:
            secrets_dir = "/secrets"
            yaml_file = "/config/config.yaml"

    settings = Settings()

    assert settings.dict() == {
        "database": {
            "password": "my_secret_database_password", 
            "username": "my_database_username"
        }
    }

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_settings_yaml-0.1.1.tar.gz (6.5 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page