Skip to main content

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

  1. Create the corresponding model for each table.
from DynamoBase import DynamoBase

class User(DynamoBase):
    table_region = "ap-southeast-2"
    table_name = "users"

  1. Query database
user = User.get_first(query={"first_name": "Jackson"})
print(user)
  1. (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
  1. (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:

DynamoDB Query Parameters

Project details


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)

Uploaded Source

Built Distribution

dynamobase-0.1.5-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page