猎鹰

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第三方库


热门话题
javapojo到org。布森。文件,反之亦然   java突然增加了G1老一代的承诺内存,减少了Eden的大小   java为什么对多个RXJava观察对象不执行并行执行?   java中的枚举是故障安全的吗?如果是,怎么做?   java是等待字符串变为相等的正确方法   java CodeAbbey挑战14个数据输入问题?   在java中的任意位置插入。util。列表   java替换html中的值   java需要帮助破译一个小堆栈跟踪:我使用的是哪种WS?   java Guice依赖项注入器空指针异常   java如何在3D引擎中实现视图剪裁平面?   JavaEclipseRCP:操作与命令需要更新   java如何使用XPAGES DesignerFacesServlet显示泰语字母(以及另一个亚洲/阿拉伯字母)   java装饰器模式问题   java我对空间复杂性的分析正确吗?   不显示java OpenGL ES 2纹理   使用java问题中的wc命令计算行数   java为什么空指针异常取决于条件的顺序?   Java日期在同一天或同一个月   java在使用lambda表达式时在变量中存储一些值