Skip to main content

SQLAlchemy-style ORM for Amazon's DynamoDB

Project description

flywheel

Master Build:

build coverage

0.1 Build:

build-0.1 coverage-0.1

Documentation:

http://flywheel.readthedocs.org/

Downloads:

http://pypi.python.org/pypi/flywheel

Source:

https://github.com/mathcamp/flywheel

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.3

  • Bug fix: Some queries fail when global index has no range key

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


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.3.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

flywheel-0.1.3-py2.py3-none-any.whl (32.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file flywheel-0.1.3.tar.gz.

File metadata

  • Download URL: flywheel-0.1.3.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for flywheel-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4521eda65fbbfda8489affd33aae4c4bd8373a95105b6428b8acf2e694054339
MD5 daa19446a4c5495ca882381803777a2f
BLAKE2b-256 b278191ba94649a3f22ab5b675339f4b8414f9069c6ab2be12907ac250fc0dce

See more details on using hashes here.

File details

Details for the file flywheel-0.1.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for flywheel-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 23b3bd94b15b599bb2290b3a7eec54826ed1e40dc70d195b58dbaf7bce55fd62
MD5 d83d499c08c5c8e11b84ffa80821f034
BLAKE2b-256 6f9e713e5cf4b701419b320e25857cb64fb178b27dd5f19f802b16a039b2e1a3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page