python orm风格的amazon(aws)dynamodb接口,使用示意图或marshmallow进行模式验证
dynamallow的Python项目详细描述
dynamodb+棉花糖==dynamallow
此程序包正在进行中-欢迎反馈/建议/etc!
两件很棒的事,一起更好!
dynamallow是一个python库,它提供了Boto v3 DynamoDB API和Marshmallow之间的集成。 它们一起为DynamoDB服务提供了一个简单的、受orm启发的接口,该接口具有完全定义的强类型 架构。
fromdynamallowimportMarshModelfrommarshmallowimportfieldsclassBook(MarshModel):classTable:name='prod-books'hash_key='isbn'read=25write=5classSchema:isbn=fields.String(validate=validate_isbn)title=fields.String()author=fields.String()publisher=fields.String()year=fields.Number()# Store new documents directly from dictionariesBook.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 constructorfoo=Book(isbn="12345678910",title="Foo",author="Mr. Bar",publisher="Publishorama")foo.save()# Or assign attributesfoo=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 keyBook.get(isbn="12345678910")# Query based on the keysBook.query(isbn__begins_with="12345")# Scan based on attributesBook.scan(author="Mr. Bar")Book.scan(author__ne="Mr. Bar")
待办事项
- 索引-目前不支持索引。
- 架构迁移
- save() 上的部分更新