Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ Full documentation available on [Read the Docs](https://awsimple.readthedocs.io/

- DynamoDB full table scans (with local cache option that only rescans if the table has changed).

- Convert back and forth between DynamoDB items and Python dictionaries automatically. Converts many common data types to DynamoDB compatible types,
including nested structures, sets, images (PIL), and Enum/StrEnum.

- True file hashing (SHA512) for S3 files (S3's etag is not a true file hash).

- Supports moto mock and localstack. Handy for testing and CI.
Expand Down
2 changes: 1 addition & 1 deletion awsimple/__version__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__application_name__ = "awsimple"
__title__ = __application_name__
__author__ = "abel"
__version__ = "7.0.0"
__version__ = "7.1.0"
__author_email__ = "j@abel.co"
__url__ = "https://github.com/jamesabel/awsimple"
__download_url__ = "https://github.com/jamesabel/awsimple"
Expand Down
2 changes: 2 additions & 0 deletions awsimple/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def dict_to_dynamodb(input_value: Any, convert_images: bool = True, raise_except
for k, v in input_value.items():
if type(k) is int:
k = str(k) # allow int as key since it is unambiguous (e.g. bool and float are ambiguous)
elif isinstance(k, Enum):
k = dict_to_dynamodb(k, False, raise_exception) # convert Enum, including StrEnum, etc. as keys
resp[k] = dict_to_dynamodb(v, convert_images, raise_exception)
elif type(input_value) is list or type(input_value) is tuple:
# converts tuple to list
Expand Down
16 changes: 16 additions & 0 deletions test_awsimple/test_dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pickle
from pathlib import Path
import time
from enum import Enum, StrEnum, auto

from PIL import Image
from ismain import is_main
Expand All @@ -31,6 +32,17 @@
dd = defaultdict(int)
dd[1] = 2


class TestEnum(Enum):
A = 1
B = 2


class TestStrEnum(StrEnum):
X = auto()
Y = auto()


sample_input = {
id_str: dict_id,
"sample1": "Test Data",
Expand All @@ -53,6 +65,8 @@
"test_date_time": datetime.datetime.fromtimestamp(1559679535, tz=timezone.utc), # 2019-06-04T20:18:55+00:00
"zero_len_string": "",
"dictim": dictim({"HI": dictim({"there": 1})}), # nested
TestEnum.A: "i am A", # Enum key
TestStrEnum.Y: "why", # StrEnum key
}


Expand Down Expand Up @@ -90,6 +104,8 @@ def test_dynamodb():
assert dynamodb_dict["42"] == "my_key_is_an_int" # test conversion of an int key to a string
assert dynamodb_dict["test_date_time"] == "2019-06-04T20:18:55+00:00"
assert dynamodb_dict["zero_len_string"] is None
assert dynamodb_dict["A"] == "i am A" # Enum key (conversion uses the Enum name)
assert dynamodb_dict["Y"] == "why" # StrEnum key

# while dictim is case-insensitive, when we convert to dict for DynamoDB it becomes case-sensitive
assert list(dynamodb_dict["dictim"]["HI"])[0] == "there"
Expand Down