DynamoDB class

class ddbmock.database.db.DynamoDB

Main database, behaves as a singleton in the sense that all instances share the same data.

If underlying store supports it, all tables schema are persisted at creation time to a special table ~*schema*~ which is an invalid DynamoDB table name so no collisions are to be expected.

Constructors

__init__

DynamoDB.__init__()

When first instanciated, __init__ checks the underlying store for potentially persisted tables. If any, it reloads there schema to make them available to the application.

In all other cases, __init__ simply loads the shared state.

Batch data manipulations

get_batch

DynamoDB.get_batch(batch)

Batch processor. Dispatches call to appropriate ddbmock.database.table.Table methods. This is the only low_level API that directly pushes throughput usage.

Parameters:batch – raw DynamoDB request batch.
Returns:dict compatible with DynamoDB API
Raises:ddbmock.errors.ValidationException if a range_key was provided while table has none.
Raises:ddbmock.errors.ResourceNotFoundException if a table does not exist.

write_batch

DynamoDB.write_batch(batch)

Batch processor. Dispatches call to appropriate ddbmock.database.table.Table methods. This is the only low_level API that directly pushes throughput usage.

Parameters:batch – raw DynamoDB request batch.
Returns:dict compatible with DynamoDB API
Raises:ddbmock.errors.ValidationException if a range_key was provided while table has none.
Raises:ddbmock.errors.ResourceNotFoundException if a table does not exist.

Database management

list_tables

DynamoDB.list_tables()

Get a list of all table names.

create_table

DynamoDB.create_table(name, data)

Create a ddbmock.database.table.Table named ‘name‘’ using parameters provided in data if it does not yet exist.

Parameters:
  • name – Valid table name. No further checks are performed.
  • data – raw DynamoDB request data.
Returns:

A reference to the newly created ddbmock.database.table.Table

Raises:

ddbmock.errors.ResourceInUseException if the table already exists.

Raises:

ddbmock.errors.LimitExceededException if more than ddbmock.config.MAX_TABLES already exist.

delete_table

DynamoDB.delete_table(name)

Triggers internal “realistic” table deletion. This implies changing the status to DELETING. Once :py:const:ddbmock.config.DELAY_DELETING has expired :py:meth:_internal_delete_table is called and the table is de-referenced from :py:attr:data.

Since :py:attr:data only holds a reference, the table object might still exist at that moment and possibly still handle pending requests. This also allows to safely return a handle to the table object.

Parameters:name – Valid table name.
Returns:A reference to ddbmock.database.table.Table named name

get_table

DynamoDB.get_table(name)

Get a handle to ddbmock.database.table.Tablename‘ is it exists.

Parameters:name – Name of the table to load.
Returns:ddbmock.database.table.Table with name ‘name
Raises:ddbmock.errors.ResourceNotFoundException if the table does not exist.

hard_reset

DynamoDB.hard_reset()

Reset and drop all tables. If any data was persisted, it will be completely lost after a call to this method. I do use in tearDown of all ddbmock tests to avaid any side effect.