Model BasicsΒΆ

This is what a model looks like:

class Tweet(Model):
    userid = Field(hash_key=True)
    id = Field(range_key=True)
    ts = Field(type=datetime, index='ts-index')
    text = Field()

The model declares the fields an object has, their data types, and the schema of the table.

Since models define the schema of a table, you can use them to create or delete tables. Every model has a meta_ field attached to it which contains metadata about the model. This metadata object has the create and delete methods.

from dynamo3 import DynamoDBConnection

connection = DynamoDBConnection.connect_to_region('us-east-1')

You can also register your models with the engine and create all the tables at once:

engine.register(User, Tweet, Message)