Skip to main content

pydantic-settings-yaml

Note: 2.x needs Pydantic>2.0,<3.0. Install 1.x if you still need Pydantic 1.x.

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
    from pydantic_settings import SettingsConfigDict

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


    class Settings(YamlBaseSettings):
        database: Database

        # configure paths to secrets directory and YAML config file
        model_config = SettingsConfigDict(
            secrets_dir="/secrets", yaml_file="/config/config.yaml")

    settings = Settings()

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

Metadata

Release files for pydantic-settings-yaml 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-settings-yaml 0.2.0
File Size Uploaded
pydantic_settings_yaml-0.2.0.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-settings-yaml 0.2.0
File Interpreter ABI Platform
pydantic_settings_yaml-0.2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 14.1 kB

Release files / pydantic_settings_yaml-0.2.0.tar.gz

Download URL pydantic_settings_yaml-0.2.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ee3c679ecd04ae045de100458387ff92bb54b435807ca8ac0726c141f63b1c8d
BLAKE2b-256 checksum
How to use checksums
03b50de91f5e0d23c0301e44029d5f64a32127f89611acc0a11fc55eb2bc90d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / pydantic_settings_yaml-0.2.0-py2.py3-none-any.whl

Download URL pydantic_settings_yaml-0.2.0-py2.py3-none-any.whl
Size 6.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e5e3a4866d124cc03bff5cca968455ce658f0382a8287c4b14e5fe91a2d6e2ef
BLAKE2b-256 checksum
How to use checksums
48a287a0b61a3078be07ab04ec574ef6c683c764590ed0d2a50d00cbb23aeae7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page