dynamorm是一个用于amazon的dynamodb服务的python对象和关系映射库。

dynamorm的Python项目详细描述


发电机

https://img.shields.io/travis/NerdWalletOSS/dynamorm.svghttps://img.shields.io/codecov/c/github/NerdWalletOSS/dynamorm.svgLatest PyPI version

此程序包正在进行中-欢迎反馈/建议/etc!

python+dynamodb

dynamo r m(发音为dynamo-r-m)是一个用于amazon DynamoDB服务的python对象和关系映射库。

该项目有两个目标:

  1. 抽象掉与底层dynamodb库的交互。对dynamodb服务的python访问具有 进化很快,从Dynamo v1 in boto to Dynamo v2 in botonew resource model in boto3。由 为其他python orms(sqlalchemy,django,peewee, etc)意味着我们可以随时为查询提供最佳实践,并在不需要的情况下利用新功能 重构任何应用程序逻辑。
  2. 将架构验证和序列化委托给更专注的库。构建“orm”语义是“容易的”, 不执行数据验证和序列化。我们同时支持MarshmallowSchematics来构建 对象架构。您可以充分利用这些库的全部功能,因为它们在 你的密码。

支持的模式验证库

示例

importdatetimefromdynamormimportDynaModel,GlobalIndex,ProjectAll# In this example we'll use Marshmallow, but you can also use Schematics too!# You can see that you have to import the schema library yourself, it is not abstracted at allfrommarshmallowimportfields# Our objects are defined as DynaModel classesclassBook(DynaModel):# Define our DynamoDB propertiesclassTable:name='prod-books'hash_key='isbn'read=25write=5classByAuthor(GlobalIndex):name='by-author'hash_key='author'read=25write=5projection=ProjectAll()# Define our data schema, each property here will become a property on instances of the Book classclassSchema:isbn=fields.String(validate=validate_isbn)title=fields.String()author=fields.String()publisher=fields.String()# NOTE: Marshmallow uses the `missing` keyword during deserialization, which occurs when we save# an object to Dynamo and the attr has no value, versus the `default` keyword, which is used when# we load a document from Dynamo and the value doesn't exist or is null.year=fields.Number(missing=lambda:datetime.datetime.utcnow().year)# 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"# In all cases they go through Schema validation, calls to .put or .save can result in ValidationErrorfoo.save()# You can then fetch, query and scan your tables.# Get on the hash key, and/or range keybook=Book.get(isbn="12345678910")# Update items, with conditions# Here our condition ensures we don't have a race condition where someone else updates the title firstbook.update(title='Corrected Foo',conditions=(title=book.title,))# Query based on the keysBook.query(isbn__begins_with="12345")# Scan based on attributesBook.scan(author="Mr. Bar")Book.scan(author__ne="Mr. Bar")# Query based on indexesBook.ByAuthor.query(author="Mr. Bar")

文档

完整的文档是从每个版本的源代码生成的,可以在以下网站上找到:

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

tests/还包含关于如何实际使用库的最完整的文档,因此鼓励您 通读它们,真正熟悉一些更高级的概念和用例。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Maven中的java,为什么要运行“mvn clean”?   java会降低图像质量。OutOfMemory异常Android   在Java8中将函数传递到流的过滤方法   jboss6。x java。lang.NoClassDefFoundError,当我将<listenerclass>包含到web时。xml java   java读取图像像素时,像素Alpha始终为255   java在迭代后跳过一行   java如何创建我自己的单链表   意图上的java空指针异常。getStringExtra.:安卓   具有连接实体的java Hibernate onetoone映射   java需要帮助在自制的仓鼠模拟器上实现启动/恢复/暂停/停止线程操作   如何测试非主方法?[Java,IntelliJ]   java jdbc自动提交(false)不起作用   java在JADE中的同一容器中创建多个代理   java OkHttp获取失败的响应正文   java Webdriver flash按钮