Dynamojo 2.0.0__tar.gz → 2.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dynamojo-2.0.0 → dynamojo-2.1.0}/PKG-INFO +4 -2
- {dynamojo-2.0.0 → dynamojo-2.1.0}/dynamojo/base.py +29 -23
- {dynamojo-2.0.0 → dynamojo-2.1.0}/dynamojo/index.py +1 -1
- {dynamojo-2.0.0 → dynamojo-2.1.0}/pyproject.toml +1 -1
- {dynamojo-2.0.0 → dynamojo-2.1.0}/README.md +0 -0
- {dynamojo-2.0.0 → dynamojo-2.1.0}/dynamojo/__init__.py +0 -0
- {dynamojo-2.0.0 → dynamojo-2.1.0}/dynamojo/config.py +0 -0
- {dynamojo-2.0.0 → dynamojo-2.1.0}/dynamojo/exceptions.py +0 -0
- {dynamojo-2.0.0 → dynamojo-2.1.0}/dynamojo/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: Dynamojo
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: ORM For Dynamodb
|
|
5
5
|
Author: Mathew Moon
|
|
6
6
|
Author-email: me@mathewmoon.net
|
|
@@ -8,6 +8,8 @@ Requires-Python: >=3.12,<4.0
|
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: Programming Language :: Python :: 3.12
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
11
13
|
Requires-Dist: boto3 (>=1.34.56,<2.0.0)
|
|
12
14
|
Requires-Dist: pydantic (>=2.0.0,<3.0.0)
|
|
13
15
|
Project-URL: Homepage, https://github.com/mathewmoon/dynamojo
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
|
+
import asyncio
|
|
5
|
+
|
|
4
6
|
from abc import ABC, abstractmethod
|
|
5
7
|
from collections import UserDict
|
|
6
8
|
from copy import deepcopy
|
|
@@ -357,8 +359,10 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
357
359
|
|
|
358
360
|
@classmethod
|
|
359
361
|
async def execute_write_transaction(cls, expressions: list[dict], **opts) -> dict:
|
|
360
|
-
res =
|
|
361
|
-
|
|
362
|
+
res = await asyncio.to_thread(
|
|
363
|
+
cls._config().dynamo_client.transact_write_items,
|
|
364
|
+
TransactItems=expressions,
|
|
365
|
+
**opts,
|
|
362
366
|
)
|
|
363
367
|
return res
|
|
364
368
|
|
|
@@ -419,7 +423,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
419
423
|
)
|
|
420
424
|
opts.update(exp)
|
|
421
425
|
|
|
422
|
-
res = self._config().dynamo_client.delete_item
|
|
426
|
+
res = await asyncio.to_thread(self._config().dynamo_client.delete_item, **opts)
|
|
423
427
|
|
|
424
428
|
return res
|
|
425
429
|
|
|
@@ -441,14 +445,16 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
441
445
|
results = []
|
|
442
446
|
|
|
443
447
|
for batch in batches:
|
|
444
|
-
res =
|
|
445
|
-
|
|
448
|
+
res = await asyncio.to_thread(
|
|
449
|
+
cls._config().dynamo_client.batch_get_item,
|
|
450
|
+
RequestItems={cls._config().table: {"Keys": batch}},
|
|
446
451
|
)
|
|
447
452
|
results += res["Responses"][cls._config().table]
|
|
448
453
|
|
|
449
454
|
while unprocessed_keys := res.get("UnprocessedKeys"):
|
|
450
|
-
res =
|
|
451
|
-
|
|
455
|
+
res = await asyncio.to_thread(
|
|
456
|
+
cls._config().dynamo_client.batch_get_item,
|
|
457
|
+
RequestItems={cls._config().table: {"Keys": unprocessed_keys}},
|
|
452
458
|
)
|
|
453
459
|
results += res["Responses"][cls._config().table]
|
|
454
460
|
|
|
@@ -474,7 +480,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
474
480
|
if key_only:
|
|
475
481
|
return opts["Key"]
|
|
476
482
|
|
|
477
|
-
res = cls._config().dynamo_client.get_item
|
|
483
|
+
res = await asyncio.to_thread(cls._config().dynamo_client.get_item, **opts)
|
|
478
484
|
|
|
479
485
|
if item := res.get("Item"):
|
|
480
486
|
return cls._construct_from_db(item)
|
|
@@ -601,7 +607,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
601
607
|
|
|
602
608
|
getLogger().debug(msg)
|
|
603
609
|
|
|
604
|
-
res = cls._config().dynamo_client.query
|
|
610
|
+
res = await asyncio.to_thread(cls._config().dynamo_client.query, **opts)
|
|
605
611
|
|
|
606
612
|
res["Items"] = [cls._construct_from_db(item) for item in res["Items"]]
|
|
607
613
|
return QueryResults(**res)
|
|
@@ -671,7 +677,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
671
677
|
fail_on_exists=fail_on_exists,
|
|
672
678
|
**kwargs,
|
|
673
679
|
)
|
|
674
|
-
return self._config().dynamo_client.put_item
|
|
680
|
+
return await asyncio.to_thread(self._config().dynamo_client.put_item, **opts)
|
|
675
681
|
|
|
676
682
|
@classmethod
|
|
677
683
|
def _resolve_alias_to_canonical(cls, field: str) -> str:
|
|
@@ -1111,7 +1117,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
1111
1117
|
)
|
|
1112
1118
|
opts["ConditionExpression"] = exp["ConditionExpression"]
|
|
1113
1119
|
|
|
1114
|
-
return cls._config().dynamo_client.update_item
|
|
1120
|
+
return await asyncio.to_thread(cls._config().dynamo_client.update_item, **opts)
|
|
1115
1121
|
|
|
1116
1122
|
@classmethod
|
|
1117
1123
|
async def delete_by_key(
|
|
@@ -1136,7 +1142,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
1136
1142
|
)
|
|
1137
1143
|
opts.update(exp)
|
|
1138
1144
|
|
|
1139
|
-
return cls._config().dynamo_client.delete_item
|
|
1145
|
+
return await asyncio.to_thread(cls._config().dynamo_client.delete_item, **opts)
|
|
1140
1146
|
|
|
1141
1147
|
async def update(
|
|
1142
1148
|
self,
|
|
@@ -1200,7 +1206,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
1200
1206
|
fail_on_missing=fail_on_missing,
|
|
1201
1207
|
**opts,
|
|
1202
1208
|
)
|
|
1203
|
-
self._config().dynamo_client.update_item
|
|
1209
|
+
await asyncio.to_thread(self._config().dynamo_client.update_item, **opts)
|
|
1204
1210
|
|
|
1205
1211
|
for field, value in (set or {}).items():
|
|
1206
1212
|
self._sync_field(field, value)
|
|
@@ -1307,7 +1313,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
1307
1313
|
)
|
|
1308
1314
|
return key
|
|
1309
1315
|
|
|
1310
|
-
def _atomic_update(
|
|
1316
|
+
async def _atomic_update(
|
|
1311
1317
|
self,
|
|
1312
1318
|
update_expression: str,
|
|
1313
1319
|
attribute_names: dict,
|
|
@@ -1335,7 +1341,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
1335
1341
|
exp["ExpressionAttributeValues"]
|
|
1336
1342
|
)
|
|
1337
1343
|
opts["ConditionExpression"] = exp["ConditionExpression"]
|
|
1338
|
-
self._config().dynamo_client.update_item
|
|
1344
|
+
await asyncio.to_thread(self._config().dynamo_client.update_item, **opts)
|
|
1339
1345
|
|
|
1340
1346
|
def _sync_field(self, field_name: str, new_val: Any) -> None:
|
|
1341
1347
|
setattr(self, field_name, new_val)
|
|
@@ -1352,7 +1358,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
1352
1358
|
ConditionExpression: ConditionBase = None,
|
|
1353
1359
|
) -> None:
|
|
1354
1360
|
self._validate_field_type(field_name, {list})
|
|
1355
|
-
self._atomic_update(
|
|
1361
|
+
await self._atomic_update(
|
|
1356
1362
|
"SET #field = list_append(#field, :items)",
|
|
1357
1363
|
{"#field": field_name},
|
|
1358
1364
|
{":items": TYPE_SERIALIZER.serialize(list(values))},
|
|
@@ -1367,7 +1373,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
1367
1373
|
ConditionExpression: ConditionBase = None,
|
|
1368
1374
|
) -> None:
|
|
1369
1375
|
self._validate_field_type(field_name, {list})
|
|
1370
|
-
self._atomic_update(
|
|
1376
|
+
await self._atomic_update(
|
|
1371
1377
|
"SET #field = list_append(:items, #field)",
|
|
1372
1378
|
{"#field": field_name},
|
|
1373
1379
|
{":items": TYPE_SERIALIZER.serialize(list(values))},
|
|
@@ -1382,7 +1388,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
1382
1388
|
ConditionExpression: ConditionBase = None,
|
|
1383
1389
|
) -> None:
|
|
1384
1390
|
self._validate_field_type(field_name, {list})
|
|
1385
|
-
self._atomic_update(
|
|
1391
|
+
await self._atomic_update(
|
|
1386
1392
|
f"REMOVE #field[{index}]",
|
|
1387
1393
|
{"#field": field_name},
|
|
1388
1394
|
None,
|
|
@@ -1400,7 +1406,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
1400
1406
|
ConditionExpression: ConditionBase = None,
|
|
1401
1407
|
) -> None:
|
|
1402
1408
|
self._validate_field_type(field_name, {list})
|
|
1403
|
-
self._atomic_update(
|
|
1409
|
+
await self._atomic_update(
|
|
1404
1410
|
f"SET #field[{index}] = :value",
|
|
1405
1411
|
{"#field": field_name},
|
|
1406
1412
|
{":value": TYPE_SERIALIZER.serialize(value)},
|
|
@@ -1423,7 +1429,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
1423
1429
|
self._validate_field_type(field_name, {int, float})
|
|
1424
1430
|
# boto3 TypeSerializer rejects float; use Decimal for wire encoding
|
|
1425
1431
|
serializable_delta = Decimal(str(delta)) if isinstance(delta, float) else delta
|
|
1426
|
-
self._atomic_update(
|
|
1432
|
+
await self._atomic_update(
|
|
1427
1433
|
"ADD #field :delta",
|
|
1428
1434
|
{"#field": field_name},
|
|
1429
1435
|
{":delta": TYPE_SERIALIZER.serialize(serializable_delta)},
|
|
@@ -1446,7 +1452,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
1446
1452
|
# See module-level warning in _dict_path_names.
|
|
1447
1453
|
self._validate_field_type(field_name, {dict})
|
|
1448
1454
|
names, expr_path = _dict_path_names(field_name, path)
|
|
1449
|
-
self._atomic_update(
|
|
1455
|
+
await self._atomic_update(
|
|
1450
1456
|
f"SET {expr_path} = :value",
|
|
1451
1457
|
names,
|
|
1452
1458
|
{":value": TYPE_SERIALIZER.serialize(value)},
|
|
@@ -1466,7 +1472,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
1466
1472
|
# See module-level warning in _dict_path_names.
|
|
1467
1473
|
self._validate_field_type(field_name, {dict})
|
|
1468
1474
|
names, expr_path = _dict_path_names(field_name, path)
|
|
1469
|
-
self._atomic_update(
|
|
1475
|
+
await self._atomic_update(
|
|
1470
1476
|
f"REMOVE {expr_path}",
|
|
1471
1477
|
names,
|
|
1472
1478
|
None,
|
|
@@ -1487,7 +1493,7 @@ class DynamojoBase(BaseModel, ABC):
|
|
|
1487
1493
|
ConditionExpression: ConditionBase = None,
|
|
1488
1494
|
) -> None:
|
|
1489
1495
|
self._validate_field_type(field_name, set())
|
|
1490
|
-
self._atomic_update(
|
|
1496
|
+
await self._atomic_update(
|
|
1491
1497
|
"SET #field = if_not_exists(#field, :value)",
|
|
1492
1498
|
{"#field": field_name},
|
|
1493
1499
|
{":value": TYPE_SERIALIZER.serialize(value)},
|
|
@@ -87,7 +87,7 @@ class IndexList(UserDict):
|
|
|
87
87
|
def get_indexes(
|
|
88
88
|
table_name: str, table_schema: dict = None, dynamo_client=None
|
|
89
89
|
) -> IndexList:
|
|
90
|
-
if not dynamo_client:
|
|
90
|
+
if not dynamo_client and not table_schema:
|
|
91
91
|
dynamo_client = boto3.client("dynamodb")
|
|
92
92
|
|
|
93
93
|
desc = table_schema or dynamo_client.describe_table(TableName=table_name)["Table"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|