Pydantic utility helpers
- Install the package from pypi
> pip install pydanticutils
- Create a pydantic settings class
class DatabaseSettings(BaseModel):
host: str = Field(default="0.0.0.0")
port: int = Field(default=5432)
class AppSettings(BaseSettings):
model_config = SettingsConfigDict(env_prefix="APP_", env_nested_delimiter="__")
log_level: str = Field(default="INFO")
database: DatabaseSettings = Field(default_factory=DatabaseSettings)
- Read a configuration file into the settings class
from pydanticutils import read_yaml
settings = read_yaml("/path/to/config.yaml", AppSettings)
This repository manages the dev environment as a Nix flake and requires Nix to be installed
> nix develop -c $SHELL
> make setup
> make test
> make pypi
pydanticutils
is released under the MIT license