Skip to main content

Load Pydantic v2 settings from AWS Secrets Manager and SSM Parameter Store

Project description

Pydantic Settings AWS

pydantic-settings-aws logo


CI codecov PyPI - Implementation PyPI - Python Version Pydantic v2 only PyPI - License Downloads

pydantic-settings-aws extends Pydantic Settings to load configuration from AWS Secrets Manager and SSM Parameter Store directly into type-safe Pydantic models, eliminating the need for manual boto3 parsing or environment variable mapping.

📖 Full documentation

✨ Why pydantic-settings-aws?

  • Define your configuration once using Pydantic models
  • Load secrets and parameters from AWS without manual boto3 code
  • Built-in validation, parsing, and type safety
  • Works with any AWS authentication method — profiles, SSO, IAM roles, access keys
  • Thread-safe and compatible with free-threaded Python

⚡ Quick Start

Add your secret to AWS Secrets Manager as a JSON object:

{
    "username": "admin",
    "password": "s3cr3t"
}

Then create your settings class:

from pydantic_settings_aws import AWSSettingsConfigDict, SecretsManagerBaseSettings


class MySettings(SecretsManagerBaseSettings):
    model_config = AWSSettingsConfigDict(
        secrets_name="my/secret"
    )

    username: str
    password: str


settings = MySettings()
print(settings.username)  # "admin"

That’s it, boto3 will resolve your AWS credentials automatically using its standard configuration chain.

✅ Features

  • Load settings from AWS Secrets Manager, SSM Parameter Store, or both simultaneously
  • Type-safe configuration with full IDE autocomplete via AWSSettingsConfigDict
  • Multi-region and multi-account support via per-field boto3 clients
  • Thread-safe client cache, compatible with free-threaded Python (3.13t, 3.14t)
  • Falls back to environment variables, dotenv, and secret files automatically

🔧 Requirements

Python Pydantic boto3
3.10+ v2 v1

💽 Installation

pip install pydantic-settings-aws

Or with uv:

uv add pydantic-settings-aws

📦 Usage

You can provide your own boto3 client or let pydantic-settings-aws create one for you. To learn how boto3 resolves credentials, see Configuring credentials.

🔐 Secrets Manager — with boto3 client

import boto3
from pydantic_settings_aws import AWSSettingsConfigDict, SecretsManagerBaseSettings


client = boto3.client("secretsmanager")


class MySettings(SecretsManagerBaseSettings):
    model_config = AWSSettingsConfigDict(
        secrets_name="my/secret",
        secrets_client=client
    )

    username: str
    password: str
    name: str | None = None


settings = MySettings()

Your secret content must be valid JSON with keys matching the field names:

{
    "username": "admin",
    "password": "admin",
    "name": "John"
}

📦 SSM Parameter Store

from typing import Annotated
from pydantic_settings_aws import AWSSettingsConfigDict, ParameterStoreBaseSettings


class MySettings(ParameterStoreBaseSettings):
    model_config = AWSSettingsConfigDict(aws_region="us-east-1")

    # pydantic-settings-aws looks for a parameter named "db_host"
    db_host: str

    # explicit parameter name via Annotated
    db_port: Annotated[str, "/myapp/prod/db/port"]

🙋🏾‍♂️ Secrets Manager — with AWS profile

from pydantic_settings_aws import AWSSettingsConfigDict, SecretsManagerBaseSettings


class MySettings(SecretsManagerBaseSettings):
    model_config = AWSSettingsConfigDict(
        secrets_name="my/secret",
        aws_region="us-east-1",
        aws_profile="dev"
    )

    username: str
    password: str

🔑 Secrets Manager — with access key

from pydantic_settings_aws import AWSSettingsConfigDict, SecretsManagerBaseSettings


class MySettings(SecretsManagerBaseSettings):
    model_config = AWSSettingsConfigDict(
        secrets_name="my/secret",
        aws_region="us-east-1",
        aws_access_key_id="aws_access_key_id",
        aws_secret_access_key="aws_secret_access_key",
        aws_session_token="aws_session_token"
    )

    username: str
    password: str

🔒 Secrets Manager — with AWS IAM Identity Center (SSO)

aws sso login --profile my-profile
from pydantic_settings_aws import AWSSettingsConfigDict, SecretsManagerBaseSettings


class MySettings(SecretsManagerBaseSettings):
    model_config = AWSSettingsConfigDict(
        secrets_name="my/secret"
    )

    username: str
    password: str

👩🏼‍⚖️ License

This project is licensed under the terms of the MIT license.

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_settings_aws-1.0.0.tar.gz (473.7 kB view details)

Uploaded Source

Built Distribution

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

pydantic_settings_aws-1.0.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_settings_aws-1.0.0.tar.gz.

File metadata

  • Download URL: pydantic_settings_aws-1.0.0.tar.gz
  • Upload date:
  • Size: 473.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pydantic_settings_aws-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3fa3bb00f649645a31af9a6e9d31d99199b83a5b9c1cf0834b5bce3c662716b3
MD5 a77282bcca4698ef7f8b257f44b3e12c
BLAKE2b-256 88bb8ad6e5b22650909315e82d63db9e98ce6b3d8a1182663ce04a3bf206d092

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_settings_aws-1.0.0.tar.gz:

Publisher: ci.yml on ceb10n/pydantic-settings-aws

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_settings_aws-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_settings_aws-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 014447ef2ae4101b5bbd937e8dc8e5382a76e46e15317f82b5254db840688f5f
MD5 e6b6dd7888a351211bfcda75dd1c459c
BLAKE2b-256 4dbbf1a768bc0ff6e250bfb40f1182a66c7264fa76a1cbc24aec8d9118527523

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_settings_aws-1.0.0-py3-none-any.whl:

Publisher: ci.yml on ceb10n/pydantic-settings-aws

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