Getting StartedΒΆ

Flywheel can be installed with pip

pip install flywheel

Here are the steps to set up a simple example model with flywheel:

# Take care of some imports
from datetime import datetime
from flywheel import Model, Field, Engine

# Set up our data model
class Tweet(Model):
    userid = Field(hash_key=True)
    id = Field(range_key=True)
    ts = Field(data_type=datetime, index='ts-index')
    text = Field()

    def __init__(self, userid, id, ts, text):
        self.userid = userid = id
        self.ts = ts
        self.text = text

# Create an engine and connect to an AWS region
engine = Engine()

# Register our model with the engine so it can create the Dynamo table

# Create the dynamo table for our registered model

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...')

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')\

# Get a specific tweet by a user
tweet = engine.query(Tweet).filter(userid='myuser', id='1234').first()

Since DynamoDB has no schema, you can set arbitrary fields on the tweets:

tweet = Tweet('myuser', '1234', datetime.utcnow(), text='super rad') = ''
tweet.retweets = 0

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

That’s enough to give you a taste. The rest of the docs have more information on creating models, writing queries, or how updates work.