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
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.5.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for dynamobase-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a03a9a9ddf326e761e6f1687615dfbdffd73e53d6a6cd96628ef7f6cbcb55ce |
|
MD5 | 8affc421d650c9795225fcc3e47bdffc |
|
BLAKE2b-256 | 64440c029cf471926cb13c2f8da227ea48afe454c8354da6227799c1ea208ad2 |