Package: falcano
FalcanoA Pythonic interface for Amazon's DynamoDB that supports Python 3 andsingle-table designbased onPynamoDB.InstallationpipinstallfalcanoBasic UsageBasic usage is nearly identical toPynamoDB.Metamust inherit fromModel.MetaandTypemust be defined for every model.Create a model that describes a model in your table.fromfalcano.modelimportModelfromfalcano.attributesimportUnicodeAttributeclassUser(Model):'''A DynamoDB User'''classMeta(Model.Meta):table_name='dynamodb-user'billing_mode='PAY_PER_REQUEST'email=UnicodeAttribute(null=True)first_name=UnicodeAttribute(range_key=True)last_name=UnicodeAttribute(hash_key=True)Type=UnicodeAttribute(default='user')Create the table if needed:User.create_table(billing_mode='PAY_PER_REQUEST')Create a new user:user=User('John','Denver')user.email='djohn@company.org'user.save()Now, search your table for all users with a last name of 'Denver' and whose first name begins with 'J':foruserinUser.query('Denver',User.first_name.startswith('J')):print(user.first_name)Examples of ways to query your table with filter conditions: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)Retrieve an existing user:try:user=User.get('John','Denver')print(user)exceptUser.DoesNotExist:print('User does not exist')Advanced UsageIndexes? No problem: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()Now query the index for all items with 0 views:foriteminTestModel.view_index.query(0):print(f'Item queried from index:{item}')It's simple!Want to use DynamoDB local? Add ahostname attribute and specify your local server.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')Single-Table Design UsageWant to follow single-table design with an index and rename theTypeattribute? No problem: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')FeaturesPython >= 3.8 supportUse ofTableboto3 resourceDynamoDB APIconditionsobjectsAuto-TypingAn ORM-like interface with query and scan filtersCompatible with DynamoDB LocalSupport for Unicode, Binary, JSON, Number, Set, and UTC Datetime attributesSupport for Global and Local Secondary IndexesAutomatic pagination for bulk operations(?)Complex queriesMultiple models per table and deserialization into objectsFeatures not yet implementedProvides iterators for working with queries, scans, that are automatically - paginatedIterators for working with Query and Scan operationsSupports the entire DynamoDB APIFull table backup/restoreBatch operations with automatic pagination