Skip to main content

Object mapper for Amazon DynamoDB

Project description

WARNING: The API changes to DynamoDBModel.__init__ in dynamodb-mapper 1.7.1 will be reverted in version 1.8.0. In the meantime, we recommend that you stick to version 1.7.0. We apologize for the inconvenience.

Dynamodb-mapper – a DynamoDB object mapper, based on boto.

Presentation

DynamoDB is a minimalistic NoSQL engine provided by Amazon as a part of their AWS product.

DynamoDB allows you to stores documents composed of unicode strings or numbers as well as sets of unicode strings and numbers. Each tables must define a hash key and may define a range key. All other fields are optional.

Dynamodb-mapper brings a tiny abstraction layer over DynamoDB to overcome some of the limitations with no performance compromise. It is highly inspired by the mature MoongoKit project

Requirements

  • Boto = 2.6.0

  • AWS account

We assume you’ve correctly set your Boto credentials.

Example usage

Quick install

$ pip install dynamodb-mapper

If you have not yet configured Boto, you may simply

$ export AWS_ACCESS_KEY_ID=<your id key here>
$ export AWS_SECRET_ACCESS_KEY=<your secret key here>

First Model

from dynamodb_mapper.model import DynamoDBModel


class DoomMap(DynamoDBModel):
    __table__ = u"doom_map"
    __hash_key__ = u"episode"
    __range_key__ = u"map"
    __schema__ = {
        u"episode": int,
        u"map": int,
        u"name": unicode,
        u"cheats": set,
    }
    __defaults__ = {
        "cheats": set([u"Konami"]),
    }

Initial Table creation

from dynamodb_mapper.model import ConnectionBorg

conn = ConnectionBorg()
conn.create_table(DoomMap, 10, 10, wait_for_active=True)

Model Usage

e1m1 = DoomMap()
e1m1.episode = 1
e1m1.map = 1
e1m1.name = u"Hangar"
e1m1.cheats = set([u"idkfa", u"iddqd", u"idclip"])
e1m1.save()


# Later on, retrieve that same object from the DB...
e1m1 = DoomMap.get(1, 1)

# query all maps of episode 1
e1_maps = DoomMap.query(hash_key=1)

# query all maps of episode 1 with 'map' hash_key > 5
from boto.dynamodb.condition import GT
e1_maps_after_5 = DoomMap.query(
    hash_key=1,
    range_key_condition=GT(5))

Contribute

Want to contribute, report a but of request a feature ? The development goes on at Ludia’s BitBucket account:

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

dynamodb-mapper-1.7.1.tar.gz (25.4 kB view details)

Uploaded Source

File details

Details for the file dynamodb-mapper-1.7.1.tar.gz.

File metadata

File hashes

Hashes for dynamodb-mapper-1.7.1.tar.gz
Algorithm Hash digest
SHA256 5665898e96dd4f9d525411fc4f27f44aa69f453687e3a8741377eefb6ef51669
MD5 cf30b5dcdbdc7f9200a1de8fab6c2e6e
BLAKE2b-256 8fc5cd5bfe89b3c2dcde6ddfe7c4c28f3d67d51cade7cf99321f9061a59ede95

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