DynamoQuery
Helper for building Boto3 DynamoDB queries.
Installation
python -m pip install dynamoquery
Usage
You can find commented usage examples in examples directory.
DynamoQuery
import boto3
from dynamo_query import DynamoQuery, DataTable
table_resource = boto3.resource("dynamodb").Table('people')
query = DynamoQuery.build_scan(
filter_expression=ConditionExpression('first_name') & ('last_name', 'in'),
).limit(
5,
).projection(
'first_name', 'last_name', 'age',
).table(
table_resource=table_resource,
table_keys=('pk', ),
)
...
# simple query
data = {
'first_name': 'John',
'last_name': ['Cena', 'Doe', 'Carmack'],
}
result_data_table = query.execute_dict(data)
for record in result_data_table.get_records():
print(record)
# batch get
data_table = DataTable.create().add_record(
{"pk": "my_pk"},
{"pk": "my_pk2"},
{"pk": "my_pk3"},
)
result_data_table = query.execute(data_table)
for record in result_data_table.get_records():
print(record)
DynamoTable
from typing import Optional
from dynamo_query import DynamoTable, DynamoDictClass
# first, define your record
@dataclass
class UserRecord(DynamoDictClass):
pk: str
email: str
name: str
points: Optional[int] = None
@DynamoDictClass.compute_key("pk")
def get_pk(self) -> str:
return self.email
# Create your dynamo table manager with your record class
class UserTable(DynamoTable[UserRecord]):
# provide a set of your table keys
table_keys = {'pk'}
record_class = UserRecord
# use this property to define your table resource
@property
def table(self) -> Any:
return boto3.resource("dynamodb").Table("user_table")
# okay, let's start using our manager
user_table = UserTable()
# add a new record to your table
user_table.upsert_record(
UserRecord(
email="user@gmail.com",
name="John User",
age=12,
)
)
# and output all the records
for user_record in user_table.scan():
print(user_record)
Development
Install dependencies with pipenv
python -m pip install pipenv
pipenv install -d
Enable pylint and mypy checks in your IDE.
Run unit tests and linting.
./scripts/before_commit.sh
Add false-positive unused entities to vulture whitelist
vulture dynamo_query --make-whitelist > vulture_whitelist.py
VSCode
Recommended .vscode/settings.json
{
"python.pythonPath": "<pipenv_path>/bin/python",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.linting.mypyEnabled": true,
"python.formatting.provider": "black"
}
PyCharm
- Install
mypyunofficial extension - Install
blackextension, enable format on save - Run
pylinton save
Versioning
dynamo_query version follows Semantic Versioning.
Metadata
Release files for dynamoquery 2.11.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dynamoquery-2.11.1-py3-none-any.whl | Python 3 | none | any | Details for dynamoquery-2.11.1-py3-none-any.whl |
Release files / dynamoquery-2.11.1-py3-none-any.whl
| Download URL | dynamoquery-2.11.1-py3-none-any.whl |
|---|---|
| Size | 42.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
218bc7e05f529486b8147f6304d1f65fe510608aee450209107db76b6b6a27e6
|
|
BLAKE2b-256 checksum How to use checksums |
f619cbfc4519a535eaa3a40353b3c5f7045cc0b52286741f9a7f701497e3d920
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
|
Security for dynamoquery 2.11.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.