boto3-assist 0.17.0__py3-none-any.whl → 0.19.0__py3-none-any.whl

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.
@@ -15,11 +15,11 @@ from boto3.dynamodb.conditions import (
15
15
  ComparisonCondition,
16
16
  ConditionBase,
17
17
  )
18
- from boto3_assist.dynamodb.dynamodb_connection import DynamoDBConnection
19
- from boto3_assist.dynamodb.dynamodb_helpers import DynamoDBHelpers
20
- from boto3_assist.dynamodb.dynamodb_model_base import DynamoDBModelBase
21
- from boto3_assist.utilities.string_utility import StringUtility
22
-
18
+ from .dynamodb_connection import DynamoDBConnection
19
+ from .dynamodb_helpers import DynamoDBHelpers
20
+ from .dynamodb_model_base import DynamoDBModelBase
21
+ from ..utilities.string_utility import StringUtility
22
+ from .dynamodb_index import DynamoDBIndex
23
23
 
24
24
  logger = Logger()
25
25
 
@@ -69,9 +69,9 @@ class DynamoDB(DynamoDBConnection):
69
69
  """
70
70
  Save an item to the database
71
71
  Args:
72
- item (dict): DynamoDB Dictionay Object or DynamoDBModelBase. Supports the "client" or
72
+ item (dict): DynamoDB Dictionary Object or DynamoDBModelBase. Supports the "client" or
73
73
  "resource" syntax
74
- table_name (str): The DyamoDb Table Name
74
+ table_name (str): The DynamoDb Table Name
75
75
  source (str, optional): The source of the call, used for logging. Defaults to None.
76
76
 
77
77
  Raises:
@@ -98,7 +98,7 @@ class DynamoDB(DynamoDBConnection):
98
98
  except Exception as e: # pylint: disable=w0718
99
99
  logger.exception(e)
100
100
  raise RuntimeError(
101
- "An error occured during model converation. The entry was not saved. "
101
+ "An error occurred during model conversion. The entry was not saved. "
102
102
  ) from e
103
103
 
104
104
  if isinstance(item, dict):
@@ -279,11 +279,11 @@ class DynamoDB(DynamoDBConnection):
279
279
 
280
280
  def query(
281
281
  self,
282
- key: dict | Key | ConditionBase | ComparisonCondition,
282
+ key: dict | Key | ConditionBase | ComparisonCondition | DynamoDBIndex,
283
+ table_name: str,
283
284
  *,
284
285
  index_name: Optional[str] = None,
285
286
  ascending: bool = False,
286
- table_name: Optional[str] = None,
287
287
  source: Optional[str] = None,
288
288
  strongly_consistent: bool = False,
289
289
  projection_expression: Optional[str] = None,
@@ -305,6 +305,17 @@ class DynamoDB(DynamoDBConnection):
305
305
  """
306
306
 
307
307
  logger.debug({"action": "query", "source": source})
308
+ if not key:
309
+ raise ValueError("Query failed: key must be provided.")
310
+
311
+ if not table_name:
312
+ raise ValueError("Query failed: table_name must be provided.")
313
+
314
+ if isinstance(key, DynamoDBIndex):
315
+ if not index_name:
316
+ index_name = key.name
317
+ # turn it into a key expected by dynamodb
318
+ key = key.key()
308
319
 
309
320
  kwargs: dict = {}
310
321
  if index_name:
@@ -330,7 +341,16 @@ class DynamoDB(DynamoDBConnection):
330
341
  raise ValueError("Query failed: table_name must be provided.")
331
342
 
332
343
  table = self.dynamodb_resource.Table(table_name)
333
- response = dict(table.query(**kwargs))
344
+ response: dict = {}
345
+ try:
346
+ response = dict(table.query(**kwargs))
347
+ except Exception as e: # pylint: disable=w0718
348
+ logger.exception(
349
+ {"source": f"{source}", "metric_filter": "query", "error": str(e)}
350
+ )
351
+ response = {"exception": str(e)}
352
+ if self.raise_on_error:
353
+ raise e
334
354
 
335
355
  return response
336
356
 
@@ -16,8 +16,8 @@ from boto3_assist.dynamodb.dynamodb_iservice import IDynamoDBService
16
16
  logger = Logger()
17
17
 
18
18
 
19
- class DynamoDBReindexer:
20
- """Reindexing your database"""
19
+ class DynamoDBReIndexer:
20
+ """ReIndexing your database"""
21
21
 
22
22
  def __init__(
23
23
  self,
@@ -12,8 +12,8 @@ import uuid
12
12
  from datetime import datetime
13
13
  from decimal import Decimal
14
14
  from typing import Any, Dict, List, TypeVar
15
- import re
16
15
  from aws_lambda_powertools import Logger
16
+ from boto3_assist.utilities.string_utility import StringUtility
17
17
 
18
18
  T = TypeVar("T")
19
19
 
@@ -119,16 +119,12 @@ class JsonConversions:
119
119
  @staticmethod
120
120
  def _camel_to_snake(value: str) -> str:
121
121
  """Converts a camelCase to a snake_case"""
122
- # Insert underscores before uppercase letters, then convert to lowercase.
123
- s1 = re.sub(r"(.)([A-Z][a-z]+)", r"\1_\2", value)
124
- return re.sub(r"([a-z0-9])([A-Z])", r"\1_\2", s1).lower()
122
+ return StringUtility.camel_to_snake(value)
125
123
 
126
124
  @staticmethod
127
125
  def _snake_to_camel(value: str) -> str:
128
126
  """Converts a value from snake_case to camelCase"""
129
- # Split the value by underscores and capitalize each component except the first.
130
- components = value.split("_")
131
- return components[0] + "".join(x.title() for x in components[1:])
127
+ return StringUtility.snake_to_camel(value)
132
128
 
133
129
  @staticmethod
134
130
  def _convert_keys(data, convert_func, deep: bool = True):
@@ -474,7 +470,7 @@ class Serialization:
474
470
  "To work around this create a boolean (bool) property named __actively_serializing_data__. \n"
475
471
  "e.g. self.__actively_serializing_data__: bool = False\n\n"
476
472
  "Only issue/raise your exception if __actively_serializing_data__ is not True. \n\n"
477
- "e.g. if not self.some_propert and not self.__actively_serializing_data__:\n"
473
+ "e.g. if not self.some_property and not self.__actively_serializing_data__:\n"
478
474
  ' raise ValueError("some_property must be set")\n\n'
479
475
  "This procedure will update the property from False to True while serializing, "
480
476
  "then back to False once serialization is complete. "
@@ -12,6 +12,7 @@ from datetime import datetime
12
12
  from decimal import Decimal
13
13
  import uuid
14
14
  import json
15
+ import re
15
16
  from aws_lambda_powertools import Logger
16
17
  from boto3_assist.utilities.datetime_utility import DatetimeUtility
17
18
 
@@ -200,7 +201,7 @@ class StringUtility:
200
201
  namespace: uuid.UUID | str, unique_string: str, case_sensitive: bool = False
201
202
  ) -> str:
202
203
  """
203
- Generates an idempotnent UUID, which is useful for creates
204
+ Generates an idempotent UUID, which is useful for creates
204
205
 
205
206
  Args:
206
207
  namespace (GUID | str): A namespace for your id, it must be a UUID or a string in a UUID format
@@ -320,3 +321,17 @@ class StringUtility:
320
321
  return False
321
322
  else:
322
323
  raise ValueError(f"Invalid boolean value: {value}")
324
+
325
+ @staticmethod
326
+ def camel_to_snake(value: str) -> str:
327
+ """Converts a camelCase to a snake_case"""
328
+ # Insert underscores before uppercase letters, then convert to lowercase.
329
+ s1 = re.sub(r"(.)([A-Z][a-z]+)", r"\1_\2", value)
330
+ return re.sub(r"([a-z0-9])([A-Z])", r"\1_\2", s1).lower()
331
+
332
+ @staticmethod
333
+ def snake_to_camel(value: str) -> str:
334
+ """Converts a value from snake_case to camelCase"""
335
+ # Split the value by underscores and capitalize each component except the first.
336
+ components = value.split("_")
337
+ return components[0] + "".join(x.title() for x in components[1:])
boto3_assist/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = '0.17.0'
1
+ __version__ = '0.19.0'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: boto3_assist
3
- Version: 0.17.0
3
+ Version: 0.19.0
4
4
  Summary: Additional boto3 wrappers to make your life a little easier
5
5
  Author-email: Eric Wilson <boto3-assist@geekcafe.com>
6
6
  License-File: LICENSE-EXPLAINED.txt
@@ -6,7 +6,7 @@ boto3_assist/connection_tracker.py,sha256=UgfR9RlvXf3A4ssMr3gDMpw89ka8mSRvJn4M34
6
6
  boto3_assist/http_status_codes.py,sha256=G0zRSWenwavYKETvDF9tNVUXQz3Ae2gXdBETYbjvJe8,3284
7
7
  boto3_assist/role_assumption_mixin.py,sha256=PMUU5yC2FUBjFD1UokVkRY3CPB5zTw85AhIB5BMtbc8,1031
8
8
  boto3_assist/session_setup_mixin.py,sha256=X-JQKyyaWNA8Z8kKgf2V2I5vsiLAH8udLTX_xepnsdQ,3140
9
- boto3_assist/version.py,sha256=ctD9pjqBvASXR0DHHzalDZFaQsnMJWDpTalYrvY3e_Y,23
9
+ boto3_assist/version.py,sha256=0oosv1io7ZLWIP51h3aW4WiUU6JK4g80JBajmF2xLAM,23
10
10
  boto3_assist/aws_lambda/event_info.py,sha256=OkZ4WzuGaHEu_T8sB188KBgShAJhZpWASALKRGBOhMg,14648
11
11
  boto3_assist/aws_lambda/mock_context.py,sha256=LPjHP-3YSoY6iPl1kPqJDwSVf1zLNTcukUunDtYcbK0,116
12
12
  boto3_assist/cloudwatch/cloudwatch_connection.py,sha256=mnGWaLSQpHh5EeY7Ek_2o9JKHJxOELIYtQVMX1IaHn4,2480
@@ -19,7 +19,7 @@ boto3_assist/cognito/cognito_connection.py,sha256=deuXR3cNHz0mCYff2k0LfAvK--9Okq
19
19
  boto3_assist/cognito/cognito_utility.py,sha256=IVZAg58nHG1U7uxe7FsTYpqwwZiwwdIBGiVTZuLCFqg,18417
20
20
  boto3_assist/cognito/jwks_cache.py,sha256=1Y9r-YfQ8qrgZN5xYPvjUEEV0vthbdcPdAIaPbZP7kU,373
21
21
  boto3_assist/cognito/user.py,sha256=qc44qLx3gwq6q2zMxcPQze1EjeZwy5Kuav93vbe-4WU,820
22
- boto3_assist/dynamodb/dynamodb.py,sha256=Xkt-dRFVqvlUkDf8P_h9VX91qfY9kLxNgpV8e-QUzbk,15992
22
+ boto3_assist/dynamodb/dynamodb.py,sha256=zq2Hqhmd3aXjnd1GAmYq5TkjMPiq_pHcMW6hClSv13Y,16679
23
23
  boto3_assist/dynamodb/dynamodb_connection.py,sha256=D4KmVpMpE0OuVOwW5g4JBWllUNkwy0hMXEGUiToAMBc,3608
24
24
  boto3_assist/dynamodb/dynamodb_helpers.py,sha256=RoRRqKjdwfC-2-gvlkLvCoNWhIoMrHm-68dkyhXI_Xk,12080
25
25
  boto3_assist/dynamodb/dynamodb_importer.py,sha256=nCKsyRQeMqDSf0Q5mQ_X_oVIg4PRnu0hcUzZnBli610,3471
@@ -28,7 +28,7 @@ boto3_assist/dynamodb/dynamodb_iservice.py,sha256=O9Aj0PFEvcuk2vhARifWTFnUwcQW5E
28
28
  boto3_assist/dynamodb/dynamodb_key.py,sha256=YD7o1EUlwVBQ55p9YCTKqAUU_np4nqtLIHnmp-BeolM,1803
29
29
  boto3_assist/dynamodb/dynamodb_model_base.py,sha256=OoSZ841YLHWTV_yx8MvVc6oHZEnvdqTYPhH9LTZ4M_M,11931
30
30
  boto3_assist/dynamodb/dynamodb_model_base_interfaces.py,sha256=yT4zDRI8vP15WVOHnCvY3FsEy_QSIta5-bnUby70Xow,747
31
- boto3_assist/dynamodb/dynamodb_reindexer.py,sha256=bCj6KIU0fQOgjkkiq9yF51PFZZr4Y9Lu3-hPlmsPG0Y,6164
31
+ boto3_assist/dynamodb/dynamodb_re_indexer.py,sha256=Y0qRrvpmjS68w8ci6Au7Hg02W_ktqhUGGALeN-9XTls,6164
32
32
  boto3_assist/dynamodb/dynamodb_reserved_words.py,sha256=p0irNBSqGe4rd2FwWQqbRJWrNr4svdbWiyIXmz9lj4c,1937
33
33
  boto3_assist/dynamodb/dynamodb_reserved_words.txt,sha256=rvctS63Cv3i9SHmPq2Unmj6RZyQ-OMqxUXsNhtbg1is,4136
34
34
  boto3_assist/dynamodb/readme.md,sha256=wNMzdRwk0qRV0kE88UUYnJos3pEK0HNjEIVkq2PATf8,1490
@@ -54,10 +54,10 @@ boto3_assist/utilities/file_operations.py,sha256=IYhJkh8wUPMvGnyDRRa9yOCDdHN9wR3
54
54
  boto3_assist/utilities/http_utility.py,sha256=_K39Fq0V4QcgklAWctUktuMjqXDTwgMld77IOUfR2zc,1282
55
55
  boto3_assist/utilities/logging_utility.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
56
56
  boto3_assist/utilities/numbers_utility.py,sha256=wzv9d0uXT_2_ZHHio7LBzibwxPqhGpvbq9HinrVn_4A,10160
57
- boto3_assist/utilities/serialization_utility.py,sha256=_soAHu2Ym6SVwMBafMPcP4t9QwtxVC03MP0cm0L3A4g,21897
58
- boto3_assist/utilities/string_utility.py,sha256=0ChxbuT37xdG4y3cKzbNTHk4T3fl8lNMdOT7L5aJBQk,10382
59
- boto3_assist-0.17.0.dist-info/METADATA,sha256=V7dNLKqmVvQFMXjNf7rIMwCRFE5vbshObvHp3ROOIIs,2875
60
- boto3_assist-0.17.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
61
- boto3_assist-0.17.0.dist-info/licenses/LICENSE-EXPLAINED.txt,sha256=WFREvTpfTjPjDHpOLADxJpCKpIla3Ht87RUUGii4ODU,606
62
- boto3_assist-0.17.0.dist-info/licenses/LICENSE.txt,sha256=PXDhFWS5L5aOTkVhNvoitHKbAkgxqMI2uUPQyrnXGiI,1105
63
- boto3_assist-0.17.0.dist-info/RECORD,,
57
+ boto3_assist/utilities/serialization_utility.py,sha256=Jc6H0cpcZjLO7tdyUZdBWHzItduLkw6sh2YQh8Hc8D8,21647
58
+ boto3_assist/utilities/string_utility.py,sha256=XxUIz19L2LFFTRDAAmdPa8Qhn40u9yO7g4nULFuvg0M,11033
59
+ boto3_assist-0.19.0.dist-info/METADATA,sha256=MHPwm_oTiAFN_Rq5puNzMqLQnEe2c3YwubHc30sb3Mg,2875
60
+ boto3_assist-0.19.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
61
+ boto3_assist-0.19.0.dist-info/licenses/LICENSE-EXPLAINED.txt,sha256=WFREvTpfTjPjDHpOLADxJpCKpIla3Ht87RUUGii4ODU,606
62
+ boto3_assist-0.19.0.dist-info/licenses/LICENSE.txt,sha256=PXDhFWS5L5aOTkVhNvoitHKbAkgxqMI2uUPQyrnXGiI,1105
63
+ boto3_assist-0.19.0.dist-info/RECORD,,