# flytekit.utils.dict_formatter

## Directory

### Methods

| Method | Description |
|-|-|
| [`format_dict()`](#format_dict) | Recursively update a dictionary with format strings with values from another dictionary where the keys match. |
| [`get_nested_value()`](#get_nested_value) | Retrieve the nested value from a dictionary based on a list of keys. |
| [`replace_placeholder()`](#replace_placeholder) | Replace a placeholder in the original string and handle the specific logic for the sagemaker service and idempotence token. |

## Methods

#### format_dict()

```python
def format_dict(
    service: str,
    original_dict: typing.Any,
    update_dict: typing.Dict[str, typing.Any],
    idempotence_token: typing.Optional[str],
) -> typing.Any
```
Recursively update a dictionary with format strings with values from another dictionary where the keys match
the format string. This goes a little beyond regular python string formatting and uses `.` to denote nested keys.

For example, if original_dict is {"EndpointConfigName": "{endpoint_config_name}"},
and update_dict is {"endpoint_config_name": "my-endpoint-config"},
then the result will be {"EndpointConfigName": "my-endpoint-config"}.

For nested keys if the original_dict is {"EndpointConfigName": "{inputs.endpoint_config_name}"},
and update_dict is {"inputs": {"endpoint_config_name": "my-endpoint-config"}},
then the result will be {"EndpointConfigName": "my-endpoint-config"}.

| Parameter | Type | Description |
|-|-|-|
| `service` | `str` | The AWS service to use |
| `original_dict` | `typing.Any` | The dictionary to update (in place) |
| `update_dict` | `typing.Dict[str, typing.Any]` | The dictionary to use for updating |
| `idempotence_token` | `typing.Optional[str]` | Hash of config -- this is to ensure the execution ID is deterministic |

**Returns:** The updated dictionary

#### get_nested_value()

```python
def get_nested_value(
    d: typing.Dict[str, typing.Any],
    keys: list[str],
) -> typing.Any
```
Retrieve the nested value from a dictionary based on a list of keys.

| Parameter | Type | Description |
|-|-|-|
| `d` | `typing.Dict[str, typing.Any]` | |
| `keys` | `list[str]` | |

#### replace_placeholder()

```python
def replace_placeholder(
    service: str,
    original_dict: str,
    placeholder: str,
    replacement: str,
) -> str
```
Replace a placeholder in the original string and handle the specific logic for the sagemaker service and idempotence token.

| Parameter | Type | Description |
|-|-|-|
| `service` | `str` | |
| `original_dict` | `str` | |
| `placeholder` | `str` | |
| `replacement` | `str` | |

---
**Source**: https://github.com/unionai/unionai-docs/blob/main/content/api-reference/flytekit-sdk/packages/flytekit.utils.dict_formatter.md
**HTML**: https://www.union.ai/docs/v1/union/api-reference/flytekit-sdk/packages/flytekit.utils.dict_formatter/
