Skip to content

Commit

Permalink
Adding examples to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Marques committed Jul 14, 2024
1 parent 36355ff commit f46fac8
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
90 changes: 89 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,94 @@

Settings management using Pydantic and Amazon Web Services.

## Installation
## 💽 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](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html#configuring-credentials).

### With secrets manager client

```python
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:

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

### 🙋🏾‍♂️ With profile name

```python
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

```python
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)

```shell
aws sso login --profile my-profile
```

```python
class AWSSecretsSettings(SecretsManagerBaseSettings):
model_config = SettingsConfigDict(
secrets_name="my/secret"
)

username: str
password: str
```
2 changes: 1 addition & 1 deletion tests/aws_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from unittest import mock

import pytest

from pydantic import ValidationError

from pydantic_settings_aws import aws

from .aws_mocks import (
Expand Down

0 comments on commit f46fac8

Please sign in to comment.