# Take care of some importsfromdatetimeimportdatetimefromflywheelimportModel,Field,Engine# Set up our data modelclassTweet(Model):userid=Field(hash_key=True)id=Field(range_key=True)ts=Field(type=datetime,index='ts-index')text=Field()def__init__(self,userid,id,ts,text):self.userid=useridself.id=idself.ts=tsself.text=text# Create an engine and connect to an AWS regionengine=Engine()engine.connect_to_region('us-east-1')# Register our model with the engine so it can create the Dynamo tableengine.register(Tweet)# Create the dynamo table for our registered modelengine.create_schema()

Now that you have your model, your engine, and the Dynamo table, you can begin
adding tweets:

tweet=Tweet('myuser','1234',datetime.utcnow(),text='@awscloud hey ''I found this cool new python library for AWS...')engine.save(tweet)

To get data back out, query it using the engine:

# Get the 10 most recent tweets by 'myuser'recent=engine.query(Tweet)\
.filter(Tweet.ts<=datetime.utcnow(),userid='myuser')\
.limit(10).all(desc=True)# Get a specific tweet by a usertweet=engine.query(Tweet).filter(userid='myuser',id='1234').first()

If you want to change a field, just make the change and sync it:

tweet.text='This tweet has been removed due to shameless promotion'tweet.sync()