猎鹰

falcano的Python项目详细描述


法尔卡诺

Amazon DynamoDB的Python接口,支持基于PynamoDB的Python 3和single-table design。在

安装

pip install falcano

基本用途

基本用法与PynamoDB几乎相同。Meta必须从Model.Meta继承,并且必须为每个模型定义{}。在

创建一个描述表中模型的模型。在

^{pr2}$

如果需要,请创建表:

User.create_table(billing_mode='PAY_PER_REQUEST')

创建新用户:

user=User('John','Denver')user.email='djohn@company.org'user.save()

现在,在您的表中搜索姓氏为“Denver”、名字以“J”开头的所有用户:

foruserinUser.query('Denver',User.first_name.startswith('J')):print(user.first_name)

使用筛选条件查询表的方法示例:

foruserinUser.query('Denver',User.email.eq('djohn@company.org')):print(user.first_name)foruserinUser.query('Denver',User.email=='djohn@company.org'):print(user.first_name)

检索现有用户:

try:user=User.get('John','Denver')print(user)exceptUser.DoesNotExist:print('User does not exist')

高级用法

索引?没问题:

fromfalcano.modelimportModelfromfalcano.indexesimportGlobalSecondaryIndex,AllProjectionfromfalcano.attributesimportNumberAttribute,UnicodeAttributeclassViewIndex(GlobalSecondaryIndex):classMeta:billing_mode='PAY_PER_REQUEST'projection=AllProjection()view=NumberAttribute(default=0,hash_key=True)classTestModel(Model):classMeta(Model.Meta):table_name='TestModel'forum=UnicodeAttribute(hash_key=True)thread=UnicodeAttribute(range_key=True)view=NumberAttribute(default=0)Type=UnicodeAttribute(default='test')view_index=ViewIndex()

现在查询索引中包含0个视图的所有项:

foriteminTestModel.view_index.query(0):print(f'Item queried from index: {item}')

很简单!在

想在本地使用DynamoDB吗?添加hostname属性并指定本地服务器。在

fromfalcano.modelsimportModelfromfalcano.attributesimportUnicodeAttributeclassUser(Model):'''    A DynamoDB User    '''classMeta(Model.Meta):table_name='dynamodb-user'host='http://localhost:8000'email=UnicodeAttribute(null=True)first_name=UnicodeAttribute(range_key=True)last_name=UnicodeAttribute(hash_key=True)Type=UnicodeAttribute(default='user')

单表设计用途

想要使用索引遵循单表设计并重命名Type属性吗?没问题:

fromfalcano.modelimportModelfromfalcano.indexesimportGlobalSecondaryIndex,AllProjectionfromfalcano.attributesimportNumberAttribute,UnicodeAttributeclassTypeIndex(GlobalSecondaryIndex):classMeta:index_name='Type'billing_mode='PAY_PER_REQUEST'projection=AllProjection()Kind=UnicodeAttribute(default=0,hash_key=True)classBaseModel(Model):classMeta(Model.Meta):table_name='single_table'# use the Kind attribute in place of Type for deserializationmodel_type='Kind'PK=UnicodeAttribute(hash_key=True)SK=UnicodeAttribute(range_key=True)TypeIndex=TypeIndex()classUser(BaseModel):email=UnicodeAttribute(null=True)Kind=UnicodeAttribute(default='user')classTeam(BaseModel):owner=UnicodeAttribute(null=True)Kind=UnicodeAttribute(default='team')

特点

  • Python>;=3.8支持
  • Tableboto3资源的利用
    • DynamoDB APIconditions对象
    • 自动键入
  • 具有查询和扫描过滤器的类似ORM的接口
  • 与发电机本地兼容
  • 支持Unicode、Binary、JSON、Number、Set和UTC Datetime属性
  • 支持全局和局部二级索引
  • 批量操作的自动分页(?)在
  • 复杂查询
  • 每个表有多个模型并反序列化为对象

尚未实现的功能

  • 提供迭代器,用于处理自动分页的查询、扫描
  • 用于处理查询和扫描操作的迭代器
  • 支持整个DynamoDB API
  • 全表备份/恢复
  • 具有自动分页功能的批处理操作

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

推荐PyPI第三方库


热门话题
安卓 xslt可与xalan cli一起使用,但不能从java代码中使用   java在spring应用程序中使用jackson进行序列化时面临的问题   Java检查Linux问题上的internet连接   当用户单击JavaSwing中的按钮时,从另一个类创建新对象   java为什么小于9,算上9?   使用Websphere 6.1生成WSDL的java未正确生成序列参数   javaq:ViewPager和OnClickListener   获取错误的java无法为child()中的参数“pathString”传递null   java组织。springframework。安全果心用户详细信息。用户详细信息创建用户   性能:单变量赋值与Objectgraph导航(Java)   java为什么资源中的CSS在spring jsp页面中不起作用?   较小的有限值双Java   java REST API如何处理post和函数错误   列出Java流API如何改进表达式