Skip to main content

Dynamo Dao

Project description

Dynamo Dao

Typed library for interacting with DynamoDb tables.

Installation

Available on PyPI

pip install dynamo-dao

Usage

The following example code shows some basic usage of this package. Note that the ExampleDao must define 4 abstract properties:

  1. table_name - Name of the DynamoDb table resource (maps directly to what you'd see on the AWS console).
  2. unique_key - The list of keys that together uniquely define an entry in the table.
  3. convert_to_dynamo - A method which takes in the object and converts it to the entry in the DynamoDb table
  4. convert_from_dynamo - The opposite of convert_to_dynamo
from typing import NamedTuple

from dynamo_dao import Dao, DynamoObject

class Example(NamedTuple):
    foo: str
    bar: int

class ExampleDao(Dao[Example]):
    table_name = "example"
    unique_key = ["foo"]

    def convert_to_dynamo(self, var: Example) -> DynamoObject:
        return {"foo": var.foo, "bar": var.bar}

    def convert_from_dynamo(self, var: DynamoObject) -> Example:
        return Example(foo=str(var["foo"]), bar=int(var["bar"]))


example_dao = ExampleDao()

example = Example(foo="hi", bar=1)

example_dao.create(example)
result = example_dao.read_one("foo", "hi")

assert example == result

Why use?

The base dao is a generic object, which means child classes will benefit from type checking on functions like read and create.

In the example above, the type of result is Example.

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

dynamo-dao-0.0.7.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

dynamo_dao-0.0.7-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file dynamo-dao-0.0.7.tar.gz.

File metadata

  • Download URL: dynamo-dao-0.0.7.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for dynamo-dao-0.0.7.tar.gz
Algorithm Hash digest
SHA256 9c3456472277acfb12ceef938ee513a023b8f08d737e9a1878e37dd094e99c4f
MD5 27a8b763140b9c6a28d434c04f5a62bf
BLAKE2b-256 1a57fb4c93e2b8a1bbc725ae2cc31b1338353c7033546f2282d9604455890821

See more details on using hashes here.

File details

Details for the file dynamo_dao-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: dynamo_dao-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for dynamo_dao-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 9390d4a6a9f8af3865d0a78b8169fbf6de3e47e18bb3bbd47143dc2b95007d54
MD5 0fac59c8699b34efef9771a76cc8a2a9
BLAKE2b-256 79180395e477f3786fe0224bfa78f42d1f512bbd53b5e937bc6a4f686233c923

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