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):
...
APIs
get_item
parameters
Name | Type | Example |
---|---|---|
query | dict | {"_id": 123} |
return: Dict or None
get_items
parameters
The parameters supported by get_items
and get_first
are as follows:
Name | Type |
---|---|
query | dict |
IndexName | String |
Select | String |
AttributesToGet | List |
Limit | int |
ConsistentRead | String |
KeyConditions | dict |
QueryFilter | dict |
ConditionalOperator | String |
ScanIndexForward | boolean |
ExclusiveStartKey | dict |
ReturnConsumedCapacity | String |
ProjectionExpression | String |
FilterExpression | boto3.dynamodb.conditions.Attr |
return: List or None
DynamoDB docs
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.6.tar.gz
(3.8 kB
view hashes)
Built Distribution
Close
Hashes for dynamobase-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51fbb70bbc5f5389a50805af948193d103075cbf653610484ee8c45344709a05 |
|
MD5 | 96fea0a4720d8733af07b5b4b411abde |
|
BLAKE2b-256 | b72dccb72c0fe1af7b53366db130d83ba2462b0188d785d8defa43f4939f1516 |