跳转到主要内容

使用Schematics或Marshmallow进行模式验证的Python ORM风格接口,用于Amazon (AWS) DynamoDB

项目描述

DynamoDB + Marshmallow == Dynamallow

https://img.shields.io/travis/borgstrom/dynamallow.svg https://img.shields.io/codecov/c/github/borgstrom/dynamallow.svg Latest PyPI version Number of PyPI downloads

此软件包正在开发中 - 欢迎反馈/建议等!

两件精彩的事情,更完美!

Dynamallow是一个Python库,它将Boto v3 DynamoDB APIMarshmallow集成在一起。它们共同提供了一个简单、受ORM启发的接口,用于具有完全定义的、强类型模式的DynamoDB服务。

from dynamallow import MarshModel
from marshmallow import fields

class Book(MarshModel):
    class Table:
        name = 'prod-books'
        hash_key = 'isbn'
        read = 25
        write = 5

    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"
foo.save()

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

# 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")

文档

完整文档可在以下网址找到

http://borgstrom.github.io/dynamallow/

TODO

  • 索引 - 目前没有对索引的支持。

  • 模式迁移

  • save()上的部分更新

项目详情


下载文件

下载适合您平台的应用程序。如果您不确定选择哪个,请了解有关安装软件包的更多信息。

源代码分发

dynamallow-0.0.3.tar.gz (10.3 kB 查看哈希值)

上传时间: 源代码

构建分发

dynamallow-0.0.3-py2.py3-none-any.whl (15.2 kB 查看哈希值)

上传时间 Python 2 Python 3

支持

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误记录StatusPageStatusPage状态页