Skip to main content

DynamORM is a Python object relation mapping library for Amazon's DynamoDB service.

Project description

DynamORM

https://img.shields.io/travis/NerdWalletOSS/dynamorm.svg https://img.shields.io/codecov/c/github/NerdWalletOSS/dynamorm.svg Latest PyPI version

This package is a work in progress – Feedback / Suggestions / Etc welcomed!

DynamORM (pronounced Dynamo-R-M) is a Python object relation mapping library for Amazon’s DynamoDB service.

The project has two goals:

  1. Abstract away the interaction with the underlying DynamoDB libraries. Python access to the DynamoDB service has evolved quickly, from Dynamo v1 in boto to Dynamo v2 in boto and then the new resource model in boto3. By providing a consistent interface that will feel familiar to users of other Python ORMs (SQLAlchemy, Django, Peewee, etc) means that we can always provide best-practices for queries and take advantages of new features without needing to refactor any application logic.

  2. Delegate schema validation and serialization to more focused libraries. Building ORM semantics is “easy”, doing data validation and serialization is not. We support both Marshmallow and Schematics for building your object schemas. You can take advantage of the full power of these libraries as they are transparently exposed in your code.

Example

from dynamorm import DynaModel

# In this example we'll use Marshmallow
# You can see that you have to import the schema library yourself, it is not abstracted at all
from marshmallow import fields

# Our objects are defined as DynaModel classes
class Book(DynaModel):
    # Define our DynamoDB properties
    class Table:
        name = 'prod-books'
        hash_key = 'isbn'
        read = 25
        write = 5

    # Define our data schema, each property here will become a property on instances of the Book class
    class Schema:
        isbn = fields.String(validate=validate_isbn)
        title = fields.String()
        author = fields.String()
        publisher = fields.String()
        year = fields.Number()


# Store new documents directly from dictionaries
Book.put({
    "isbn": "12345678910",
    "title": "Foo",
    "author": "Mr. Bar",
    "publisher": "Publishorama"
})

# Work with the classes as objects.  You can pass attributes from the schema to the constructor
foo = Book(isbn="12345678910", title="Foo", author="Mr. Bar",
           publisher="Publishorama")
foo.save()

# Or assign attributes
foo = Book()
foo.isbn = "12345678910"
foo.title = "Foo"
foo.author = "Mr. Bar"
foo.publisher = "Publishorama"

# In all cases they go through Schema validation, calls to .put or .save can result in ValidationError
foo.save()

# You can then fetch, query and scan your tables.
# Get on the hash key, and/or range key
Book.get(isbn="12345678910")

# Query based on the keys
Book.query(isbn__begins_with="12345")

# Scan based on attributes
Book.scan(author="Mr. Bar")
Book.scan(author__ne="Mr. Bar")

Documentation

Full documentation can be found online at:

https://nerdwalletoss.github.io/dynamorm/

TODO

These are broken down by milestone release.

0.1.0

  • Indexes – Currently there is no support for indexes.

  • Partial updates on save()

1.0.0

  • Schema Migrations

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

dynamorm-0.1.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

dynamorm-0.1.1-py2.py3-none-any.whl (17.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dynamorm-0.1.1.tar.gz.

File metadata

  • Download URL: dynamorm-0.1.1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dynamorm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 563320c4e2f9dc144c7d028f90f65d34bd6c1da7818872febcd6037a97ec4ec9
MD5 0bfa72c4c8df6f6e65d6a9703cdcf2b2
BLAKE2b-256 6a5080d1be9a1695d06a14455d778a4ef2f776b17303e507a84cf4a82126e72b

See more details on using hashes here.

File details

Details for the file dynamorm-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for dynamorm-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0f986c84b299cf1f8e04c5786a87b27fc468fa0742dbb523d6be264917458673
MD5 c73de01097a39afac42d2a3b4cf1b27e
BLAKE2b-256 bb65618d6c77695c77ad5c029d3c624263590352f8edf6af6974be13b7e98968

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