Skip to content

Commit f214259

Browse files
committed
add example code snippets to item encryptor functions
1 parent 5756541 commit f214259

File tree

1 file changed

+40
-0
lines changed
  • src/dynamodb_encryption_sdk/encrypted

1 file changed

+40
-0
lines changed

src/dynamodb_encryption_sdk/encrypted/item.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ def encrypt_dynamodb_item(item, crypto_config):
3737
# type: (dynamodb_types.ITEM, CryptoConfig) -> dynamodb_types.ITEM
3838
"""Encrypt a DynamoDB item.
3939
40+
>>> from dynamodb_encryption_sdk.encrypted.item import encrypt_dynamodb_item
41+
>>> plaintext_item = {
42+
... 'some': {'S': 'data'},
43+
... 'more': {'N': '5'}
44+
... }
45+
>>> encrypted_item = encrypt_dynamodb_item(
46+
... item=plaintext_item,
47+
... crypto_config=my_crypto_config
48+
... )
49+
4050
.. note::
4151
4252
This handles DynamoDB-formatted items and is for use with the boto3 DynamoDB client.
@@ -112,6 +122,16 @@ def encrypt_python_item(item, crypto_config):
112122
# type: (dynamodb_types.ITEM, CryptoConfig) -> dynamodb_types.ITEM
113123
"""Encrypt a dictionary for DynamoDB.
114124
125+
>>> from dynamodb_encryption_sdk.encrypted.item import encrypt_python_item
126+
>>> plaintext_item = {
127+
... 'some': 'data',
128+
... 'more': 5
129+
... }
130+
>>> encrypted_item = encrypt_python_item(
131+
... item=plaintext_item,
132+
... crypto_config=my_crypto_config
133+
... )
134+
115135
.. note::
116136
117137
This handles human-friendly dictionaries and is for use with the boto3 DynamoDB service or table resource.
@@ -130,6 +150,16 @@ def decrypt_dynamodb_item(item, crypto_config):
130150
# type: (dynamodb_types.ITEM, CryptoConfig) -> dynamodb_types.ITEM
131151
"""Decrypt a DynamoDB item.
132152
153+
>>> from dynamodb_encryption_sdk.encrypted.item import decrypt_python_item
154+
>>> encrypted_item = {
155+
... 'some': {'B': b'ENCRYPTED_DATA'},
156+
... 'more': {'B': b'ENCRYPTED_DATA'}
157+
... }
158+
>>> decrypted_item = decrypt_python_item(
159+
... item=encrypted_item,
160+
... crypto_config=my_crypto_config
161+
... )
162+
133163
.. note::
134164
135165
This handles DynamoDB-formatted items and is for use with the boto3 DynamoDB client.
@@ -204,6 +234,16 @@ def decrypt_python_item(item, crypto_config):
204234
# type: (dynamodb_types.ITEM, CryptoConfig) -> dynamodb_types.ITEM
205235
"""Decrypt a dictionary for DynamoDB.
206236
237+
>>> from dynamodb_encryption_sdk.encrypted.item import decrypt_python_item
238+
>>> encrypted_item = {
239+
... 'some': Binary(b'ENCRYPTED_DATA'),
240+
... 'more': Binary(b'ENCRYPTED_DATA')
241+
... }
242+
>>> decrypted_item = decrypt_python_item(
243+
... item=encrypted_item,
244+
... crypto_config=my_crypto_config
245+
... )
246+
207247
.. note::
208248
209249
This handles human-friendly dictionaries and is for use with the boto3 DynamoDB service or table resource.

0 commit comments

Comments
 (0)