3.2. Read an Item

Items can be retrieved from a table in a dict-like style. If the table only has a hash key, items are accessed from the value of the hash key. If it has a hash key and a sort key, they’re accessed by a tuple of (hash key value, sort key value).

from models import Movie

from awstin.dynamodb import DynamoDB


def get_movie(title, year):
    dynamodb = DynamoDB()
    table = dynamodb[Movie]

    item: Movie = table[year, title]

    return item


if __name__ == "__main__":
    movie = get_movie("The Big New Movie", 2015)
    if movie:
        print("Get movie succeeded:")
        print(type(movie))
        print(movie.serialize())