Skip to main content

An Async Pythonic Interface to DynamoDB

Project description

Async fork of PynamoDB powered by aiobotocore. Requires Python 3.10+. This fork tracks brunobelloni/AioPynamoDB and publishes fork builds on PyPI as as-aiopynamodb.

Installation

From PyPI:

$ pip install as-aiopynamodb -U

From GitHub:

$ pip install git+https://github.com/AppSolves/AioPynamoDB#egg=as-aiopynamodb

Basic Usage

Create a model that describes your DynamoDB table.

from aiopynamodb.models import Model
from aiopynamodb.attributes import UnicodeAttribute

class UserModel(Model):
    """
    A DynamoDB User
    """
    class Meta:
        table_name = "dynamodb-user"
    email = UnicodeAttribute(null=True)
    first_name = UnicodeAttribute(range_key=True)
    last_name = UnicodeAttribute(hash_key=True)

AioPynamoDB allows you to create the table if needed (it must exist before you can use it!):

await UserModel.create_table(read_capacity_units=1, write_capacity_units=1)

Create a new user:

user = UserModel("John", "Denver")
user.email = "djohn@company.org"
await user.save()

Now, search your table for all users with a last name of ‘Denver’ and whose first name begins with ‘J’:

async for user in UserModel.query("Denver", UserModel.first_name.startswith("J")):
    print(user.first_name)

Examples of ways to query your table with filter conditions:

async for user in UserModel.query("Denver", UserModel.email=="djohn@company.org"):
    print(user.first_name)

Retrieve an existing user:

try:
    user = await UserModel.get("John", "Denver")
    print(user)
except UserModel.DoesNotExist:
    print("User does not exist")

Advanced Usage

Want to use indexes? No problem:

from aiopynamodb.models import Model
from aiopynamodb.indexes import GlobalSecondaryIndex, AllProjection
from aiopynamodb.attributes import NumberAttribute, UnicodeAttribute

class ViewIndex(GlobalSecondaryIndex):
    class Meta:
        read_capacity_units = 2
        write_capacity_units = 1
        projection = AllProjection()
    view = NumberAttribute(default=0, hash_key=True)

class TestModel(Model):
    class Meta:
        table_name = "TestModel"
    forum = UnicodeAttribute(hash_key=True)
    thread = UnicodeAttribute(range_key=True)
    view = NumberAttribute(default=0)
    view_index = ViewIndex()

Now query the index for all items with 0 views:

async for item in TestModel.view_index.query(0):
    print("Item queried from index: {0}".format(item))

It’s really that simple.

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

as_aiopynamodb-1.0.4.tar.gz (96.8 kB view details)

Uploaded Source

Built Distribution

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

as_aiopynamodb-1.0.4-py3-none-any.whl (62.8 kB view details)

Uploaded Python 3

File details

Details for the file as_aiopynamodb-1.0.4.tar.gz.

File metadata

  • Download URL: as_aiopynamodb-1.0.4.tar.gz
  • Upload date:
  • Size: 96.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for as_aiopynamodb-1.0.4.tar.gz
Algorithm Hash digest
SHA256 b108f3377d6583c5c96bdbc12e2eaaf65f353b874eaa2a47dce8c84322545b7e
MD5 4693a4b8ca5a4fb14e27db20cb44bbc5
BLAKE2b-256 e6dca63de8adb358232ebc5958ebbf99a24a4d5e8d370a863663dbe473edac1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for as_aiopynamodb-1.0.4.tar.gz:

Publisher: release.yaml on AppSolves/AioPynamoDB

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file as_aiopynamodb-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: as_aiopynamodb-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 62.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for as_aiopynamodb-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f264b47861e28d3b2b5ae85004afbd6e2648fe55468b837ae93c5be6daa33617
MD5 e8b22c76d27000cc131fa48cb2efa1ab
BLAKE2b-256 13e7e4814e843b2ad8afb8e3a9e22dc3b516ac745c0849c1a0ba609b7f3e8f0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for as_aiopynamodb-1.0.4-py3-none-any.whl:

Publisher: release.yaml on AppSolves/AioPynamoDB

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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