Skip to main content

A simple boto3/Pydantic implementation of DynamoDB Single Table Design and related utilities.

Project description

Simple Single Table

Latest Version: 4.0.1

simplesingletable is a Python library that offers an abstraction layer for AWS DynamoDB operations, particularly for those tables using single-table design. It uses Pydantic to define the models, and tries to be as "batteries-included" based on how I personally have come to use DynamoDb.

I've used and written variations of this same code many times, and finally decided to try and package it all up into a single library I could pip install and use whenever I needed cheap, easy, fast storage with few access patterns. So far this is working quite well for the way I use DynamoDb and the assumptions that are true for me, such as:

  • My apps are generally pretty small scale -- a few hundred users at a time max
  • My collection sizes are pretty small -- tens or hundreds of thousands, not millions or billions

In this scenario I've found DynamoDb to be an extremely valuable tool that can perform extremely fast and consistently, and essentially for free or very little cost. I believe most of these tools and techniques would scale beyond that, but cannot personally attest to it.

Key Features

There are many ways to use DynamoDb. These are the things I've come to want:

  • A single table where I can store different types of Objects (Pydantic Models)
  • Automatic resource ID creation using a lexicographically sortable ID (via ulid-py); this is very useful for setting up alternative access patterns using the secondary indices and having them sort by creation date of the objects.
  • Simple way to list, paginate, and filter by object type, sortable by last updated time, seamlessly blending DynamoDb filter expressions and server side filtering on the loaded Pydantic models using simple python functions
  • Automatic versioning for created resources -- every update generates a new version, and the complete version history is maintained and easily accessed; additionally the code prevents simultaneous writes from the same version; updates can only be performed from the latest version of an object.
  • Powerful query function for enabling secondary access patterns using GSIs as needed

Installation:

pip install simplesingletable

Usage

Docs, examples, and access patterns coming soon!

Here's a brief demo of how to utilize:

# How to Use:
# 1. Define a Resource:
# Resources are essentially DynamoDB items. They can be defined by subclassing `DynamodbVersionedResource`:

from simplesingletable import DynamodbVersionedResource, DynamoDBMemory


class MyTestResource(DynamodbVersionedResource):
    some_field: str
    bool_field: bool
    list_of_things: list[str | int | bool | float]


# 2. CRUD Operations
from logzero import logger

dynamodb_memory = DynamoDBMemory(logger=logger, table_name="my-dynamodb-table")
resource = dynamodb_memory.create_new(MyTestResource, {})
retrieved = dynamodb_memory.read_existing(resource.resource_id, MyTestResource)
updated_resource = dynamodb_memory.update_existing(retrieved, {})

More coming soon...

Testing:

The package includes a comprehensive test suite to ensure reliability and robustness. Use the test_simplesingletable.py as a reference for the functionalities available until more documentation is available.

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

simplesingletable-4.0.1.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simplesingletable-4.0.1-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file simplesingletable-4.0.1.tar.gz.

File metadata

  • Download URL: simplesingletable-4.0.1.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.11

File hashes

Hashes for simplesingletable-4.0.1.tar.gz
Algorithm Hash digest
SHA256 90aa2dd07fb5ab6e7fc85f89cc3e3afb0d943738c8f7fcfc962077456d83f681
MD5 e2699a9c39b48027041dddabed940416
BLAKE2b-256 a70fb4299b8a7fac6039ba272d23b539ab675bccb8d5a5dddf15d9e9802556ec

See more details on using hashes here.

File details

Details for the file simplesingletable-4.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for simplesingletable-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73f67f28cc93de2d1fc6ebbb6ecfdc1b558d69f79c7c29e44f6b7ccca67f74fc
MD5 0eb68bf8a234ba4228a87aef10bafcea
BLAKE2b-256 8eeb8be8e08d452461fe01fea1bf8be212498c901d4bba08be8e5444caa50b61

See more details on using hashes here.

Supported by

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