Skip to main content

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

Project description

Simple Single Table

Latest Version: 1.4.0

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-1.4.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

simplesingletable-1.4.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for simplesingletable-1.4.0.tar.gz
Algorithm Hash digest
SHA256 0c952db62aac5281312d478c47ceeb0aeb0f2740573c1286eeb3ddab3389284d
MD5 f9a635a665405e9eee2fb79610450841
BLAKE2b-256 8e50588a3fbfd3381c15387b3bf24c6c826ed4d33dbffddd1d3c930b5eb278d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simplesingletable-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5f4d3f223c74db15c774420edc17e9172403e88bc263a184031208dd3e47fd0
MD5 1edcaf29e783f2c0097a93f128f55a22
BLAKE2b-256 c00a5fcde31fe47c6be4e69fa02b69ab3e5c16e67cbd15fdf2023275bc8b42b3

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