44from __future__ import annotations
55
66from typing import (
7- Iterator , KeysView , Tuple , Union , Any , Optional , Iterable , Dict , Set , List , Mapping , Sequence ,
8- cast , TypeAlias
7+ Iterator , Tuple , Union , Any , Optional , Iterable , Dict , Set , List , Mapping , Sequence ,
8+ cast
99)
1010from collections .abc import ValuesView , ItemsView , KeysView , MutableMapping
1111from decimal import Decimal
2323DynamoDBKeyPrimitiveTypes = (str , bytes , bytearray , int , Decimal )
2424"""DynamoDB primary key primitive choices."""
2525
26- DynamoDBKeyPrimitive : TypeAlias = Union [str , bytes , bytearray , int , Decimal ]
26+ DynamoDBKeyPrimitive = Union [str , bytes , bytearray , int , Decimal ]
2727"""DynamoDB primary key primitive."""
2828
29- DynamoDBKeySimple : TypeAlias = Tuple [DynamoDBKeyPrimitive ]
29+ DynamoDBKeySimple = Tuple [DynamoDBKeyPrimitive ]
3030"""DynamoDB simple primary key type (a partition key only)."""
3131
32- DynamoDBKeyComposite : TypeAlias = Tuple [DynamoDBKeyPrimitive , DynamoDBKeyPrimitive ]
32+ DynamoDBKeyComposite = Tuple [DynamoDBKeyPrimitive , DynamoDBKeyPrimitive ]
3333"""DynamoDB composite primary key type (a partition key and a sort key)."""
3434
35- DynamoDBKeyAny : TypeAlias = Union [DynamoDBKeySimple , DynamoDBKeyComposite ]
35+ DynamoDBKeyAny = Union [DynamoDBKeySimple , DynamoDBKeyComposite ]
3636"""Any DynamoDB primary key type."""
3737
38- DynamoDBKeySimplified : TypeAlias = Union [DynamoDBKeyPrimitive , DynamoDBKeyComposite ]
38+ DynamoDBKeySimplified = Union [DynamoDBKeyPrimitive , DynamoDBKeyComposite ]
3939"""A simplified DynamoDB key type: a primitive in case of simple primary key,
4040and a tuple in the case of composite key."""
4141
42- DynamoDBKeyName : TypeAlias = Union [Tuple [str ], Tuple [str , str ]]
42+ DynamoDBKeyName = Union [Tuple [str ], Tuple [str , str ]]
4343"""DynamoDB primary key name type"""
4444
4545DynamoDBValueTypes = (
4848)
4949"""DynamoDB value type choices."""
5050
51- DynamoDBValue : TypeAlias = Union [
51+ DynamoDBValue = Union [
5252 bytes , bytearray , str , int , Decimal ,bool ,
5353 Set [int ], Set [Decimal ], Set [str ], Set [bytes ], Set [bytearray ],
5454 Sequence [Any ], Mapping [str , Any ], None ,
5555]
5656"""DynamoDB value type."""
5757
58- DynamoDBItemType : TypeAlias = Mapping [str , DynamoDBValue ]
58+ DynamoDBItemType = Mapping [str , DynamoDBValue ]
5959"""DynamoDB item type."""
6060
6161logger = logging .getLogger (__name__ )
@@ -322,14 +322,22 @@ def scan(self, **kwargs) -> Iterator[DynamoDBItemType]:
322322 for item in response ["Items" ]:
323323 yield item
324324
325- def get_item (self , keys : DynamoDBKeySimplified , ** kwargs ) -> DynamoDBItemType :
325+ def get_item (self , keys : DynamoDBKeySimplified , ** kwargs ) -> DynamoDBItemAccessor :
326326 """Retrieves a single item from the table.
327327
328328 The value(s) of the item's key(s) should be specified.
329329
330+ This method returns a dictionary wrapper over a single item from the table. You can access
331+ the attributes of the item as if it was a common Python dictionary (i.e. with the ``[]``
332+ operators), but the wrapper also allows you to modify directly the single attribute values
333+ of the item, as shown in the example.
334+
330335 Example::
331336
332- print(mapping.get_item("my_key"))
337+ my_item = mapping.get_item("my_key")
338+ print(my_item)
339+ my_item["title"] = "FooBar"
340+
333341
334342 Args:
335343 keys: The key value. This can either be a simple Python type,
@@ -343,7 +351,7 @@ def get_item(self, keys: DynamoDBKeySimplified, **kwargs) -> DynamoDBItemType:
343351 KeyError: If no item can be found under this key in the table.
344352
345353 Returns:
346- A single item from the table.
354+ A dictionary wrapper over a single item from the table.
347355 """
348356 key_params = self ._create_key_param (keys )
349357 logger .debug ("Performing a get_item operation on %s table" , self .table .name )
0 commit comments