python中一个简单的 DynamoDB ORM框架

网友投稿 773 2022-10-23

python中一个简单的 DynamoDB ORM框架

python中一个简单的 DynamoDB ORM框架

KIWI - DynamoDB ORM for Python

Kiwi is an AWS DynamoDB ORM for Python. Kiwi depends on boto and supports Python2.7, Python3.4 at least.

Installation

Install Kiwi from source:

$ git clone https://github.com/papaya-mobile/kiwi.git$ cd kiwi$ python setup.py sdist$ pip install dist/kiwi-x.x.x.tar.gz

Basic usage

The table, Field of Kiwi will be used to define a DynamoDB Model:

from boto.dynamodb2 import connect_to_regionfrom boto.dynamodb2.types import NUMBERfrom kiwi import metadatafrom kiwi import Tablefrom kiwi import Fieldfrom kiwi import HashKeyField, RangeKeyFieldconnection = connect_to_region("us-east-1")metadata.configure(connection=connection)class User(Table): id = HashKeyField(data_type=NUMBER) name = Field()class UserTask(Table): user_id = HashKeyField(data_type=NUMBER) task_id = RangeKeyField() name = Field() time = Field() done = Field(data_type=NUMBER, default=0)

After define a model, it's very easy to insert items:

>>> User(id=1, name='Aaron').save()>>> UserTask(user_id=1, task_id='first', name='test').save()>>> UserTask(user_id=1, task_id='second', name='test').save() >>> UserTask(user_id=1, task_id='fifth', name='test').save()

You may also get and query items easily:

>>> User.get(1)>>> UserTask.get(1, 'second') >>> UserTask.query().filter(UserTask.user_id==1, UserTask.task_id.beginswith_('f')).all()[, ]

Documentation

You can read the docs online: http://papaya-kiwi.readthedocs.org/en/latest/

You can also generate documentation by yourself. The docs are created by sphinx, which can be installed via pip.

pip install sphinxcd kiwi/docsmake html

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:编程之美
下一篇:数字转换成中文大小写
相关文章

 发表评论

暂时没有评论,来抢沙发吧~