Skip to main content

Settings management using AWS Secrets Manager and Pydantic

Project description

Pydantic Settings AWS

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

Settings management using Pydantic and Amazon Web Services / Secrets Manager.

💽 Installation

Install using pip install -U pydantic-settings-aws.

📜 Example

You can create and manage your own secrets manager client or leave it to pydantic-settings-aws.

If you want to leave to pydantic-settings-aws to deal with boto3, you can either pass your credential information or leave it to boto3 to figure it out.

To check how boto3 will look for your configurations, check Configuring credentials.

🧑🏻‍💻 With secrets manager client

import boto3
from pydantic_settings_aws import SecretsManagerBaseSettings


client = boto3.client("secretsmanager")


class AWSSecretsSettings(SecretsManagerBaseSettings):
    model_config = SettingsConfigDict(
        secrets_name="my/secret",
        secrets_client=client
    )

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

my_settings = AWSSecretsSettings()

And your secrets manager should be:

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

🙋🏾‍♂️ With profile name

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

    username: str
    password: str

🔑 With access key

class AWSSecretsSettings(SecretsManagerBaseSettings):
    model_config = SettingsConfigDict(
        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

🔒 With AWS IAM Identity Center (SSO)

aws sso login --profile my-profile
class AWSSecretsSettings(SecretsManagerBaseSettings):
    model_config = SettingsConfigDict(
        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-0.1.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

pydantic_settings_aws-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydantic_settings_aws-0.1.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for pydantic_settings_aws-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0cf72e537495d7f4256ed8b354e5286d3cfe3c6f942be17f267808134d87a054
MD5 8abfefe943a60d7b38172f9771348aa0
BLAKE2b-256 1c37342c77ddd069e8eba0f2f86855fbbc31fa7991f1002ce1043f70d0984fa8

See more details on using hashes here.

File details

Details for the file pydantic_settings_aws-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_settings_aws-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85c37773e3706d0e2120088b4cb93c545cb58eba80d6326aebc800d78338f7ad
MD5 42f3ecb2a20464b24e2353e4082ffb28
BLAKE2b-256 c44dc46e2d48a291286daa710e8eb2ef7bfbf5995579e5ebd1f16a45722ce309

See more details on using hashes here.

Supported by

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