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:
table_name
- Name of the DynamoDb table resource (maps directly to what you'd see on the AWS console).unique_key
- The list of keys that together uniquely define an entry in the table.convert_to_dynamo
- A method which takes in the object and converts it to the entry in the DynamoDb tableconvert_from_dynamo
- The opposite ofconvert_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.2.tar.gz
(2.8 kB
view details)
Built Distribution
File details
Details for the file dynamo-dao-0.0.2.tar.gz
.
File metadata
- Download URL: dynamo-dao-0.0.2.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33d528532bfa4c8590f3908f5048d829b03f5068a8a92b59d12749b7469593a7 |
|
MD5 | 9b8b8812092bb0685c9ad812bd2e9891 |
|
BLAKE2b-256 | 485d70d1105dea72fe63d083bac8035efc20fa0ca44c1d65f4c5675df19278e6 |
File details
Details for the file dynamo_dao-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: dynamo_dao-0.0.2-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36bcbe70de949e78c6789e5c7deb61d48ff0c3a1eb074464654851036941e343 |
|
MD5 | dd8c9165be2a8f349ccb5dcca0325c8e |
|
BLAKE2b-256 | 6d726a98761ee612280e76f80c44945d9ba7b9a3f7ad2825c43a2551002dce81 |