Key class

class ddbmock.database.key.Key(name, typename)

Abstraction layer over DynamoDB Keys in ddbmock.database.item.Item

Constructors

__init__

Key.__init__(name, typename)

High level Python constructor

Parameters:
  • name – Valid key name. No further checks are performed.
  • typename – Valid key typename. No further checks are performed.

from_dict

classmethod Key.from_dict(data)

Alternate constructor which deciphers raw DynamoDB request data before ultimately calling regular __init__ method.

See __init__() for more insight.

Parameters:data – raw DynamoDB request data.
Returns:fully initialized Key instance

Key manipulations

read

Key.read(key)

Parse a key as specified by DynamoDB API and return its value as long as its typename matches typename

Parameters:key – Raw DynamoDB request key.
Returns:the value of the key
Raises:ddbmock.errors.ValidationException if field types does not match

to_dict

Key.to_dict()

Return the key as a Python dict.

Returns:Serialized version of the key definition metadata compatible with DynamoDB API syntax.

PrimaryKey

class ddbmock.database.key.PrimaryKey(name, typename)

Special marker to provide distinction between regulat Keys and PrimaryKey