Async fork of PynamoDB powered by aiobotocore. Requires Python 3.10+.
Installation
From PyPI:
$ pip install aiopynamodb
From GitHub:
$ pip install git+https://github.com/brunobelloni/AioPynamoDB#egg=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.
Metadata
Release files for aiopynamodb 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiopynamodb-1.0.1.tar.gz | 94.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiopynamodb-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 155.4 kB
Release files / aiopynamodb-1.0.1.tar.gz
| Download URL | aiopynamodb-1.0.1.tar.gz |
|---|---|
| Size | 94.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85b4c85205caa1c49bd90e366d01f76b91b5cb38af131e1db89bc20dc9c34f63
|
|
BLAKE2b-256 checksum How to use checksums |
31ea2a8b95a5093b780cfc68086664a0af115e4221824dbbb80a7eeba4c2d204
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / aiopynamodb-1.0.1-py3-none-any.whl
| Download URL | aiopynamodb-1.0.1-py3-none-any.whl |
|---|---|
| Size | 60.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
150905f2508661f5c43a6cf6a9bae1ce6b1d927a812cdc276e1098ad5bc17416
|
|
BLAKE2b-256 checksum How to use checksums |
ab47328db67c33a7d63e5d1463c4d0480c1481751c81262ae7133e2da5ef05a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|