Skip to main content

Calculated/copied attributes to support advanced single-table design in DynamoDB

Project description

PynamoDB Polymorph

This package has utilities that are useful when using PynamoDB with a single-table (polymorphic) design and overloading Global Secondary Indexes.

Take for example a Publisher class that needs to use a compound key of their type prefix and their name. If you rely on callers doing the copy in code there is possibility for them to update the name without also updating the GSI sort key that contains the name. The CompoundTemplateAttribute uses string.Template templating to fill unicode or numeric attributes into a string template to build keys automatically.

class Publisher(Base, discriminator="Publisher"):
    name = UnicodeAttribute()
    description = UnicodeAttribute(default="")
    gsi1_pk = CopiedDiscriminatorAttribute(source="cls")
    gsi1_sk = CompoundTemplateAttribute(
        template="PUBLISHER#$name",
        attrs=["name"],
    )

The template above will take any value in name and fill it in to the template, so name="Random Book Publishing House" will become a gsi1_sk="PUBLISHER#Random Book Publishing House".

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

pynamodb-polymorph-0.1.1.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file pynamodb-polymorph-0.1.1.tar.gz.

File metadata

  • Download URL: pynamodb-polymorph-0.1.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0

File hashes

Hashes for pynamodb-polymorph-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a7d48b7a66e4c8c7296fd9a69b989b4ca0b826b1f62a3687c32dffe644fd7200
MD5 889e9289b1147f0229f1072a37d3373b
BLAKE2b-256 1615c80b9c146935fbd3d20fa5157e35c2d4923c94fa79d36600a4695368fa1c

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