You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Query DynamoDB like MongoDB. A lightweight JSON model that simplifies DynamoDB's obscure query operations. It retains all original parameters and supports DynamoDB versions and future upgrades.
What can be done:
Query condition is JSON format
No need to consider complex expressions no matter query or update
Column names can be any reserved keywords
Return the correct int, float, number types
What can't be done:
Create, modify, and drop DynamoDB tables
Install
pip install dynamobase
Use
Basic try
from DynamoBase import DynamoBase
DynamoBase.table_region = "ap-southeast-2"
DynamoBase.table_name = "users"
DynamoBase.session = ... # if you need specific settings like aws profile, credentials etc.
# get a single item
user = DynamoBase.get_item(query={"first_name": "Jackson"})
print(user)
# get a list of items, IndexName is optional
# query relate to KeyConditions, filter relate to FilterExpression
user = DynamoBase.get_items(query={"first_name": "Jackson"}, IndexName='ix_name')
print(user)
# get the first item, IndexName is optional
user = DynamoBase.get_first(query={"first_name": "Jackson"}, IndexName='ix_name')
print(user)
# insert an item
DynamoBase.put_item(Item={"first_name": "Jackson"})
# update an item, Item is part or all of item
DynamoBase.update_item(query={"first_name": "Jackson"}, Item={'field': 12345})
# delete an item
DynamoBase.delete_item(query={"first_name": "Jackson"})
Recommendation
Create the corresponding model for each table.
from DynamoBase import DynamoBase
class User(DynamoBase):
table_region = "ap-southeast-2"
table_name = "users"
Query database
user = User.get_first(query={"first_name": "Jackson"})
print(user)
(Optional) You can also create a base-model to configure common properties, such as region and credentials
from DynamoBase import DynamoBase
class BaseModel(DynamoBase):
table_region = "ap-southeast-2"
from BaseModel import BaseModel
class User(BaseModel):
table_name = "users"
(Optional) Extend your classes to meet your business needs
Query DynamoDB like MongoDB. A lightweight JSON model that simplifies DynamoDB's obscure query operations. It retains all original parameters and supports DynamoDB versions and future upgrades.