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"
DynamoBase.session = ... # if you need specific settings like aws profile, credentials etc.
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.7.tar.gz
(3.8 kB
view hashes)
Built Distribution
Close
Hashes for dynamobase-0.1.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e31ce1f5b9e10f441407d9f0ec660f3e7671ce62c86a67d24c95a1c85c509a67 |
|
MD5 | 2ae1f82e6a2d4851580a7b3c3fef9353 |
|
BLAKE2b-256 | 5a33d03227781121e8e6938e3f4a7507917a957beab14e1ff13da8a28260ca3b |