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.3.tar.gz (94.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.3-py3-none-any.whl (60.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: as_aiopynamodb-1.0.3.tar.gz
  • Upload date:
  • Size: 94.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.3.tar.gz
Algorithm Hash digest
SHA256 8e41c25ad3db0d09f3cc7e111dee0328a08fbc032bc347394f9476738735b9c4
MD5 0dc62fe36872aaa883f5db400cf7b1ec
BLAKE2b-256 5e962646db96254ab7df213a1f2e457f62ead3e58cb45abb5c01ca9b3fbc511d

See more details on using hashes here.

Provenance

The following attestation bundles were made for as_aiopynamodb-1.0.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: as_aiopynamodb-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 60.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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 91c3355d913cda7425c06500c2c96700fed59e42a929e0e0f6da82c03aaf749d
MD5 19dfa3577b3d6ac7505de4c73c661568
BLAKE2b-256 9508876e04554a67f7afda91e4f191b2fbade56c52b7bc7abe4b27379ccae814

See more details on using hashes here.

Provenance

The following attestation bundles were made for as_aiopynamodb-1.0.3-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