A Json Model that is the easiest way to query DynamoDB.
Project description
DynamoBase
A Json Model that is the easiest way to query DynamoDB.
Install
pip install DynamoBase simplejson boto3
Use
Basic try
from DynamoBase import DynamoBase
DynamoBase.table_region = "ap-southeast-2"
DynamoBase.table_name = "users"
user = DynamoBase.get_item(query={"first_name": "Jackson"})
print(user)
user = DynamoBase.get_items(query={"first_name": "Jackson"}, IndexName='ix_name')
print(user)
# Doesn't need parameter IndexName when query primary key, GSI does
user = DynamoBase.get_first(query={"first_name": "Jackson"})
print(user)
user = DynamoBase.put_item(Item={"first_name": "Jackson"})
print(user)
user = DynamoBase.update_item(query={"first_name": "Jackson"}, doc={'field': 12345})
print(user)
user = DynamoBase.delete_item(query={"first_name": "Jackson"})
print(user)
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 MyModel(DynamoBase):
table_region = "ap-southeast-2"
table_name = "lt_feedbacks"
from MyModel import MyModel
class User(MyModel):
pass
- (Optional) Extend your classes to meet your business needs
from DynamoBase import DynamoBase
class MyModel(DynamoBase):
table_region = "ap-southeast-2"
table_name = "lt_feedbacks"
@classmethod
def get_item(cls, **kwargs):
...
@classmethod
def other_method(cls, **kwargs):
...
Parameters
Supports all DynamoDB query properties:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
DynamoBase-0.1.4.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for DynamoBase-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f47e9e02b0e7354e45ba2567bfebe465ab915b252823f17e2236357c74a2030 |
|
MD5 | c6118bfa5e081fedec75dd17cb2ff5a4 |
|
BLAKE2b-256 | 9cd5e9acda00e1b7610ec6030351906d94da33241929e4793744fa224fede7b5 |