SQLAlchemy-style ORM for Amazon's DynamoDB
Project description
flywheel
- Master Build:
- 0.1 Build:
- Documentation:
- Downloads:
- Source:
Object mapper for Amazon’s DynamoDB
Getting Started
This is what a basic model looks like (schema taken from this DynamoDB API documentation)
from flywheel import Model, Field, GlobalIndex class GameScore(Model): __metadata__ = { 'global_indexes': [ GlobalIndex('GameTitleIndex', 'title', 'top_score') ], } userid = Field(hash_key=True) title = Field(range_key=True) top_score = Field(data_type=int) top_score_time = Field(data_type=datetime) wins = Field(data_type=int) losses = Field(data_type=int) def __init__(self, title, userid): self.title = title self.userid = userid
Create a new top score:
>>> score = GameScore('Master Blaster', 'abc') >>> score.top_score = 9001 >>> score.top_score_time = datetime.utcnow() >>> engine.sync(score)
Get all top scores for a user:
>>> scores = engine.query(GameScore).filter(userid='abc').all()
Get the top score for Galaxy Invaders:
>>> top_score = engine.query(GameScore).filter(title='Galaxy Invaders')\ ... .first(desc=True)
Atomically increment a user’s “wins” count on Alien Adventure:
>>> score = GameScore('Alien Adventure', 'abc') >>> score.incr_(wins=1) >>> engine.sync(score)
Get all scores on Comet Quest that are over 9000:
>>> scores = engine.query(GameScore).filter(GameScore.top_score > 9000, ... title='Comet Quest').all()
Changelog
0.1.2
Bug fix: Field names can begin with an underscore
Feature: Models have a nice default __init__ method
0.1.1
Bug fix: Can call incr_() on models that have not been saved yet
Bug fix: Model comparison with None
0.1.0
First public release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flywheel-0.1.2.tar.gz
(27.0 kB
view hashes)
Built Distribution
Close
Hashes for flywheel-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4db73aa31d6b51382feb758fbe6cc35fa113e82dac2fbcb33b450420c9980e90 |
|
MD5 | ecd9362e32bf5f5e46300209a0ea7bc4 |
|
BLAKE2b-256 | cb662a63b8c4e7e15e221f573344302148546d09fc41074a6bbac670a0b080eb |