Skip to main content

Dokklib-DB (UNMAINTAINED)

CI Join the chat at https://gitter.im/dokklib/dokklib-db

Dokklib-DB is a Python library for the DynamoDB single table pattern.

Features

  • Simple, Pythonic query interface on top of Boto3. No more nested dict literals!
  • Type safety for primary keys and indices (for documentation and data integrity).
  • Easy error handling.
  • Full type hint & unit test coverage + integration testing.

Documentation

Install

Install with:

pip install "boto3>=1.10.34,<2" dokklib-db

Requires Python 3.6 or later.

Note that Boto3 is not specified as an installation requirement for Dokklib-DB, so you have to install it separately (like in the example command above). The reason for this is to make Dokklib-DB easier to use in AWS Lambda where Boto3 is part of the default environment. The earliest supported Boto3 version is 1.10.34 which is the same version as the Boto3 package in the Python 3 AWS Lambda environments.

Example usage

import dokklib_db as db


class User(db.EntityName):
    """User entity name.

    Key value: unique user name, eg. 'alice'.
    Example key: 'USER#alice'.

    """


class Group(db.EntityName):
    """Group entity name.

    Key value: unique group name, eg. 'my-group'.
    Example key: 'GROUP#my-group'.

    """


table = db.Table('SingleTable')

# Construct entity keys.
pk_alice = db.PartitionKey(User, 'alice')
pk_bob = db.PartitionKey(User, 'bob')
sk_group1 = db.SortKey(Group, 'group1')

# Add users to group one.
# Insert is a `PutItem` operation that fails if the item already exists.
table.insert(pk_alice, sk_group1)
table.insert(pk_bob, sk_group1)

# Get all users in group one.
pk_group = db.PartitionKey(Group, 'group1')
user_prefix = db.PrefixSortKey(User)
group_members = table.query_prefix(pk_group, user_prefix, 
    global_index=db.InversePrimaryIndex())

print(group_members)
# [{'PK': 'alice'}, {'PK': 'bob'}]

# Move users from group one to group two atomically.
sk_group2 = db.SortKey(Group, 'group2')
table.transact_write_items([
    db.DeleteArg(pk_alice, sk_group1),
    db.DeleteArg(pk_bob, sk_group1),
    db.InsertArg(pk_alice, sk_group2),
    db.InsertArg(pk_bob, sk_group2)
])

Status

The project is no longer maintained.

The library is in beta and under heavy development as I'm working on it while building a serverless project that relies on it. I have only implemented parts of the DynamoDB API that I needed so far, but I'm planning on achieving full coverage. Feature and pull requests are welcome. (Please open an issue, before starting work on a pull request to avoid wasted effort.)

Release files for dokklib-db 0.0.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dokklib-db 0.0.15
File Size Uploaded
dokklib_db-0.0.15.tar.gz 38.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dokklib-db 0.0.15
File Interpreter ABI Platform
dokklib_db-0.0.15-py3-none-any.whl Python 3 none any Details

Total release size:59.7 kB

Release files / dokklib_db-0.0.15.tar.gz

Download URL dokklib_db-0.0.15.tar.gz
Size 38.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a2701045287aba5625f7b5fddb211d22581b67315c919f722b194fea09839852
BLAKE2b-256 checksum
How to use checksums
fa577e6b400ed488a908390cec202cf12fad756d9167c814b3bb1333301804a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.15

Release files / dokklib_db-0.0.15-py3-none-any.whl

Download URL dokklib_db-0.0.15-py3-none-any.whl
Size 20.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f0e12255d63502854895fe1045b3cc8d8f5c3e3dcd4e865830b62ceac00a60b
BLAKE2b-256 checksum
How to use checksums
d6ef28e07dd4167dc581cd2ebeeb27fa1d09496a44efc8585c8d93e8e80f3ae3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.15

Release history Release notifications | RSS feed

This release

0.0.15 This release

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page