SOPS extension for pydantic-settings
.
This package allows you to read SOPS files into a pydantic-settings
object.
You can install this package via
pip install pydantic-settings-sops
# or
pixi add pydantic-settings-sops
To use pydantic-settings-sops, adjust your settings sources by defining a custom settings_customise_sources
.
For more information on pydantic-settings
, please visit the official documentation.
from pydantic_settings import (
BaseSettings,
PydanticBaseSettingsSource,
SettingsConfigDict,
)
from pydantic_settings_sops import SOPSConfigSettingsSource
class SettingsExample(BaseSettings):
model_config = SettingsConfigDict(
yaml_file="secrets.yaml"
)
foobar: str
@classmethod
def settings_customise_sources(
cls,
settings_cls: BaseSettings,
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]:
return (init_settings, SOPSConfigSettingsSource(settings_cls))
This project is managed by pixi. You can install the package in development mode using:
git clone https://github.com/pavelzw/pydantic-settings-sops
cd pydantic-settings-sops
pixi run pre-commit-install
pixi run postinstall
pixi run test