GetRequest

A GetRequest is used to perform a get_item transaction with DynamoDB. It is used for retrieving a single item by its primary key. The entire primary key must be provided (including a sort key if it is defined on the table)

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GetItem.html

class cerami.request.GetRequest(client, tablename='', request_attributes=None, reconstructor=None)

A class to perform the get_item request

__init__(client, tablename='', request_attributes=None, reconstructor=None)

constructor for base request

Parameters
  • client – A boto3.client('dynamodb')

  • tablename – the name of the table to perform the request on

  • request_attributes

    a dict of SearchAttribute objects whose keys represent options that can be passed to client upon execution For example, it may include a FilterExpression key whose value is a SearchAttribute that resolves to a string of filters. This is typically None but can be used to manually build requests:

    Parent.scan.filter(Parent.name == 'Mom').project(Parent.name)
    # The search_attributes can be manually specified
    ScanRequest(client=client, tablename='parents', search_attributes={
        'FilterExpression': SearchAttribute('name = Mom'),
        'ProjectionExpression': SearchAttribute('name'),
    })
    

  • reconstructor – a Reconstructor object

add_attribute(attr_class, name, value)

add a search attribute to a to the request_attributes dict

All search attributes must be unique keys. When the key already exists, it will update that value by calling add(). Depending on the attr_class, this can overwrite, append, change the value of the existing search attribute.

Parameters
  • attr_class – a SearchAttribute class

  • name – the name of the attribute

  • value – the value that will be added to the SearchAttribute

For example:

Person.scan.limit(10)
# or ...
Person.scan.add_attribute(SearchAttribute, 'Limit', 10)
build()

build the dict used by dynamodb

Returns

a dict whose keys matching the keys of the request_attributes and whose values are string versions of each attribute

For example:

User.scan.filter(User.email == 'test@test.com').build()
{
    "TableName": "Users",
    "FilterExpression": "#__email = :_email_dpxqm",
    "ExpressionAttributeNames": {
        "#__email": "email"
    },
    "ExpressionAttributeValues": {
        ":_email_dpxqm": {
            "S": "test@test.com"
        }
    }
}
execute()

perform the get_item request

Returns

a GetResponse object built from the get_item response

For example:

Person.get.key(Person.email == 'test@test.com').execute()
key(*expressions)

return a new Request setup with the Key attribute

Adds the Key to the request_attributes dict

Parameters

*expressions – a list of BaseExpressions

Returns

the caller of the method. This allows for chaning

For example:

Person.get.key(Person.email == 'test@test.com').build()
{
    "TableName": "people",
    "Key": {
        "email": {
            "S": "test@test.com"
        }
    }
}
project(*datatypes_or_expressions)

return a new Request setup with project attributes

Adds the ProjectionExpression, ExpressionAttributeNames to the request_attributes dict

Parameters

*datatypes – a list of datatypes. List.index() and Map.key() can be passed to project specific nested attributes

Returns

the caller of the method. This allows for chaining

For example:

Person.scan.project(Person.name, Person.email)
{
    "TableName": "people",
    "ProjectionExpression": "#__name  :_name_lwxqt, #__email  :_email_dvsyj",
    "ExpressionAttributeNames": {
        "#__name": "name",
        "#__email": "email"
    }
}