Socket
Book a DemoInstallSign in
Socket

pydantic-ssm-settings

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pydantic-ssm-settings

AWS SSM support for Pydantic Settings

1.1.2
pipPyPI
Maintainers
2

pydantic-ssm-settings

Integrate AWS Systems Manager Parameter Store with Pydantic Settings.

Usage

The simplest way to use this module is to inhert your settings from SsmBaseSettings. This add the SsmSettingsSource as a custom settings source and enabled passing source configuration (e.g. _ssm_prefix, _ssm_client) via kwargs when initializing a settings class.

from pydantic_ssm_settings import SsmBaseSettings


class WebserviceSettings(SsmBaseSettings):
    some_val: str
    another_val: int

WebserviceSettings(_ssm_prefix="/prod/webservice")

Alternatively, configuration may be specified within the settings class via BaseModel.model_config:

from pydantic_ssm_settings import SsmSettingsConfigDict

class WebserviceSettings(SsmBaseSettings):
    model_config = SsmSettingsConfigDict(ssm_prefix="/prod/webservice")
    some_val: str
    another_val: int


WebserviceSettings()

If it is preferred to avoid altering the baseclass of a settings model, the source can be manually added and configured as such:

from typing import Tuple, Type
from pydantic_settings import (
    BaseSettings,
    EnvSettingsSource,
    InitSettingsSource,
    PydanticBaseSettingsSource,
    SecretsSettingsSource,
)
from pydantic_ssm_settings import SsmSettingsConfigDict, SsmSettingsSource

class WebserviceSettings(BaseSettings):
    model_config = SsmSettingsConfigDict(ssm_prefix="/asdf")
    foo: str

    def settings_customise_sources(
        self,
        settings_cls: Type[BaseSettings],
        init_settings: InitSettingsSource,
        env_settings: EnvSettingsSource,
        dotenv_settings: PydanticBaseSettingsSource,
        file_secret_settings: SecretsSettingsSource,
    ) -> Tuple[PydanticBaseSettingsSource, ...]:
        return (
            init_settings,
            env_settings,
            dotenv_settings,
            file_secret_settings,
            SsmSettingsSource(settings_cls),
        )

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.