Skip to main content

AWS SSM support for Pydantic Settings

Project description

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),
        )

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_ssm_settings-1.1.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_ssm_settings-1.1.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_ssm_settings-1.1.2.tar.gz.

File metadata

  • Download URL: pydantic_ssm_settings-1.1.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pydantic_ssm_settings-1.1.2.tar.gz
Algorithm Hash digest
SHA256 b50228d1d863c1e97d9dfd018f7fdfe85fb65ab54f16a4f258b58de91a98b3a9
MD5 c568e6bede97b68933a57d8d19811798
BLAKE2b-256 579dbdb5acf5c072d517126f9c1058680d36019e6296a6ce027d7b1b17dc6cde

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_ssm_settings-1.1.2.tar.gz:

Publisher: main.yaml on developmentseed/pydantic-ssm-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pydantic_ssm_settings-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_ssm_settings-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0b01c00c64930bfad755ac78fafa9dbc4b3ea0a3b2b3a6a0f8eb1fd4d02b3c3b
MD5 c98308af68cae445a9b4d038d218ee45
BLAKE2b-256 e9c530dcdae47685d9402b7514a7afc003217bfd3922fa01ee9c32a7135f61c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_ssm_settings-1.1.2-py3-none-any.whl:

Publisher: main.yaml on developmentseed/pydantic-ssm-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page