Skip to main content

A Dynamodb ORM

Project description

Cerami

Cerami is a python library that hopefully provides some sanity to boto3's DynamoDB client. Its intended use is as a library to help define table data through the creation of models and create sane, readable, and reproducable DynamoDB requests.

Please read the Full Documentation_

.. _Full Documentation: https://cerami.readthedocs.io/en/latest/

Quickstart

Install

.. code-block::

pip install cerami

I have boto3 and aws credentials set up

.. code-block:: python

# create the db singleton
import boto3
from cerami import Cerami

dynamodb = boto3.client('dynamodb')
db = Cerami(dynamodb)

.. code-block:: python

# create classes that inherit from the singleton
from cerami.datatype import String, Set, Datetime
from cerami.decorators import primary_key

@primary_key('name', 'artist')
class Album(db.Model):
__tablename__ = "Albums"

name = String()
artist = String()
songs = Set(String())
released_date = Datetime()

# Some Query Examples
Album.scan \
.filter(Album.released_date.begins_with("1996")) \
.execute()

Album.query \
.key(Album.name == "The Black Album") \
.execute()

Album.get \
.key(Album.name == "Reasonable Doubt") \
.key(Album.artist == "Jay-Z") \
.execute()

I have never used boto3 or dynamodb before

You can run DynamoDB locally!

You need to install the aws2 cli and have dynamo db running locally. Dynamodb requires java to run locally as well so good luck if you dont have it. Try these steps first and see how it goes.

Download DynamoDB Locally

1. `Download DynamoDB Locally`_
2. Unzip/Untar the content
3. Move to somewhere you wont lose it.

.. _Download DynamoDB Locally: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html

Download the AWS2 CLI
~~~~~~~~~~~~~~~~~~~~~
1. `Download the AWS2 CLI`_
2. Follow the install instructions

.. _Download the AWS2 CLI`: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html

Configure the AWS2 CLI
~~~~~~~~~~~~~~~~~~~~~~
In order to run DynamoDB locally, you need to configure your aws as such:

.. code-block::

    aws2 configure


.. code-block::

    # These are the actual values to use with the local dynamodb instance
    AWS Access Key ID: "fakeMyKeyId"
    AWS Secret Access Key: "fakeSecretAccessKey"
    us-west-1

Starting DynamoDB Locally

.. code-block::

java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb

Creating a DynamoDB Table

.. code-block:: python

    import boto3

    dynamodb = boto3.client('dynamodb', endpoint_url="http://localhost:8000")

    dynamodb.create_table(
        TableName='Albums',
        KeySchema=[
            {
                'AttributeName': 'name',
                'KeyType': 'HASH'  #Partition key
            },
            {
                'AttributeName': 'artist',
                'KeyType': 'Range', # Sort key
            },
        ],
        AttributeDefinitions=[
            {
                'AttributeName': 'name',
                'AttributeType': 'S'
            },
            {
                'AttributeName': 'artist',
                'AttributeType': 'S'
            },
        ],
        ProvisionedThroughput={
            'ReadCapacityUnits': 10,
            'WriteCapacityUnits': 10
        }
    )


Using Cerami
~~~~~~~~~~~~
.. code-block:: python

    # Create the db singleton
    import boto3
    from cerami import Cerami

    dynamodb = boto3.client('dynamodb', endpoint_url="http://localhost:8000")
    db = Cerami(dynamodb)

.. code-block:: python

    # create classes that inherit from the singleton
    from cerami.datatype import String, Set, Datetime
    from cerami.decorators import primary_key

    @primary_key('name', 'artist')
    class Album(db.Model):
	__tablename__ = "Albums"

	name = String()
	artist = String()
	songs = Set(String())
	released_date = Datetime()



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

cerami-0.3.8.tar.gz (40.3 kB view details)

Uploaded Source

Built Distribution

cerami-0.3.8-py3-none-any.whl (90.8 kB view details)

Uploaded Python 3

File details

Details for the file cerami-0.3.8.tar.gz.

File metadata

  • Download URL: cerami-0.3.8.tar.gz
  • Upload date:
  • Size: 40.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

File hashes

Hashes for cerami-0.3.8.tar.gz
Algorithm Hash digest
SHA256 e8890d57b0fa1116d746ce7a60d414df04db08b69b81287116edaf5b0dfdcf0e
MD5 355acc4a66f8a486ad039d991392c237
BLAKE2b-256 85d61c86f0c84e4c77e44e8e65abfc582e734d30cc9b727ec577645c4ca1a11a

See more details on using hashes here.

File details

Details for the file cerami-0.3.8-py3-none-any.whl.

File metadata

  • Download URL: cerami-0.3.8-py3-none-any.whl
  • Upload date:
  • Size: 90.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

File hashes

Hashes for cerami-0.3.8-py3-none-any.whl
Algorithm Hash digest
SHA256 667306b785a21b67d591efffe6ac505f01dd6bebee754bb9a990d2835a3e017c
MD5 e80f7f344a108f75625f0c8674d035ce
BLAKE2b-256 1cd4ab642745781eaf69ae7caff2dbafc8b1abf7b7e7398e325a6a073767bb99

See more details on using hashes here.

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