finalsa-common-models 1.0.0__py3-none-any.whl → 2.0.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.
- finalsa/common/models/__init__.py +2 -3
- finalsa/common/models/models/__init__.py +8 -1
- finalsa/common/models/models/meta.py +10 -0
- finalsa/common/models/models/sqs_response.py +5 -55
- finalsa_common_models-2.0.0.dist-info/METADATA +87 -0
- finalsa_common_models-2.0.0.dist-info/RECORD +9 -0
- {finalsa_common_models-1.0.0.dist-info → finalsa_common_models-2.0.0.dist-info}/WHEEL +1 -2
- {finalsa_common_models-1.0.0.data/data → finalsa_common_models-2.0.0.dist-info/licenses}/LICENSE.md +1 -1
- finalsa/common/models/models/sqs_message.py +0 -27
- finalsa/common/models/py.typed +0 -0
- finalsa_common_models-1.0.0.dist-info/LICENSE.md +0 -21
- finalsa_common_models-1.0.0.dist-info/METADATA +0 -24
- finalsa_common_models-1.0.0.dist-info/RECORD +0 -13
- finalsa_common_models-1.0.0.dist-info/top_level.txt +0 -2
- finalsa_common_models-1.0.0.dist-info/zip-safe +0 -1
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
from finalsa.common.models.models import (
|
|
2
|
-
|
|
2
|
+
Meta,
|
|
3
3
|
SqsReponse,
|
|
4
4
|
parse_message_attributes,
|
|
5
5
|
to_message_attributes
|
|
6
6
|
)
|
|
7
7
|
|
|
8
|
-
__version__ = "1.0.0"
|
|
9
8
|
|
|
10
9
|
__all__ = [
|
|
11
|
-
"
|
|
10
|
+
"Meta",
|
|
12
11
|
"SqsReponse",
|
|
13
12
|
"parse_message_attributes",
|
|
14
13
|
"to_message_attributes",
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
from .functions import parse_message_attributes, to_message_attributes
|
|
2
|
-
from .sqs_message import SqsMessage
|
|
3
2
|
from .sqs_response import SqsReponse
|
|
3
|
+
from .meta import Meta
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"Meta",
|
|
7
|
+
"SqsReponse",
|
|
8
|
+
"parse_message_attributes",
|
|
9
|
+
"to_message_attributes",
|
|
10
|
+
]
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
from datetime import datetime, timezone
|
|
2
1
|
from typing import Dict, Optional, Union
|
|
3
|
-
from uuid import UUID, uuid4
|
|
4
2
|
from pydantic import BaseModel
|
|
5
|
-
from
|
|
6
|
-
from .sqs_message import SqsMessage
|
|
3
|
+
from orjson import loads
|
|
7
4
|
from .functions import parse_message_attributes
|
|
8
5
|
|
|
9
6
|
|
|
@@ -17,38 +14,10 @@ class SqsReponse(BaseModel):
|
|
|
17
14
|
md5_of_message_attributes: Optional[str] = ""
|
|
18
15
|
message_attributes: Optional[Dict] = {}
|
|
19
16
|
|
|
20
|
-
@staticmethod
|
|
21
|
-
def correlation_id_from_attributes(attributes: Dict) -> Optional[str]:
|
|
22
|
-
correlation_id = attributes.get('correlation_id', None)
|
|
23
|
-
if not correlation_id:
|
|
24
|
-
return None
|
|
25
|
-
if isinstance(correlation_id, str):
|
|
26
|
-
return correlation_id
|
|
27
|
-
if isinstance(correlation_id, dict) and 'Type' in correlation_id and 'Value' in correlation_id:
|
|
28
|
-
return correlation_id["Value"]
|
|
29
|
-
return None
|
|
30
|
-
|
|
31
|
-
def get_correlation_id(self, payload: Optional[Dict] = {}) -> Union[str, UUID]:
|
|
32
|
-
correlation_id = self.correlation_id_from_attributes(self.message_attributes)
|
|
33
|
-
if correlation_id:
|
|
34
|
-
return correlation_id
|
|
35
|
-
correlation_id = self.correlation_id_from_attributes(self.attributes)
|
|
36
|
-
if correlation_id:
|
|
37
|
-
return correlation_id
|
|
38
|
-
if 'correlation_id' in payload:
|
|
39
|
-
return payload['correlation_id']
|
|
40
|
-
return str(uuid4())
|
|
41
|
-
|
|
42
17
|
@staticmethod
|
|
43
18
|
def __is_sns_message__(content: Dict) -> bool:
|
|
44
19
|
return 'Type' in content and content['Type'] == 'Notification'
|
|
45
20
|
|
|
46
|
-
@staticmethod
|
|
47
|
-
def __is_sqs_message__(content: Dict) -> bool:
|
|
48
|
-
return ('id' in content and
|
|
49
|
-
'topic' in content and
|
|
50
|
-
'payload' in content)
|
|
51
|
-
|
|
52
21
|
def parse_from_sns(self) -> Dict:
|
|
53
22
|
payload = loads(self.body)
|
|
54
23
|
if self.__is_sns_message__(payload):
|
|
@@ -70,34 +39,15 @@ class SqsReponse(BaseModel):
|
|
|
70
39
|
content = self.__parse_from_sns__(content)
|
|
71
40
|
return content
|
|
72
41
|
|
|
73
|
-
def
|
|
74
|
-
|
|
75
|
-
if isinstance(content, dict) and self.__is_sqs_message__(content):
|
|
76
|
-
if 'correlation_id' not in content:
|
|
77
|
-
content['correlation_id'] = str(self.get_correlation_id(content))
|
|
78
|
-
return SqsMessage(
|
|
79
|
-
id=UUID(content['id']),
|
|
80
|
-
topic=content['topic'],
|
|
81
|
-
payload=content['payload'],
|
|
82
|
-
correlation_id=content['correlation_id'],
|
|
83
|
-
timestamp=content['timestamp']
|
|
84
|
-
)
|
|
85
|
-
return SqsMessage(
|
|
86
|
-
id=uuid4(),
|
|
87
|
-
topic=self.topic,
|
|
88
|
-
payload=content,
|
|
89
|
-
correlation_id=self.get_correlation_id(content),
|
|
90
|
-
timestamp=datetime.now(timezone.utc).isoformat()
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
def get_sqs_message(self) -> SqsMessage:
|
|
42
|
+
def get_payload(self) -> Union[str, Dict]:
|
|
94
43
|
try:
|
|
95
44
|
content = loads(self.body)
|
|
96
45
|
except Exception:
|
|
97
|
-
return self.
|
|
46
|
+
return self.body
|
|
98
47
|
if self.__is_sns_message__(content):
|
|
99
48
|
content = self.__parse_from_sns__(content)
|
|
100
|
-
|
|
49
|
+
return content
|
|
50
|
+
return loads(self.body)
|
|
101
51
|
|
|
102
52
|
@classmethod
|
|
103
53
|
def from_boto_response(cls, response: Dict):
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: finalsa-common-models
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Common models for Finalsa
|
|
5
|
+
Project-URL: Homepage, https://github.com/finalsa/finalsa-common-models
|
|
6
|
+
Author-email: Luis Jimenez <luis@finalsa.com>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2025 Luis Diego Jiménez Delgado
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
License-File: LICENSE.md
|
|
29
|
+
Keywords: common,finalsa,models
|
|
30
|
+
Requires-Python: >=3.10
|
|
31
|
+
Requires-Dist: orjson>=3.10.16
|
|
32
|
+
Requires-Dist: pydantic>=2.11.1
|
|
33
|
+
Requires-Dist: python-dateutil>=2.9.0.post0
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# Finalsa Async Models
|
|
37
|
+
|
|
38
|
+
Finalsa Async Models is a Python library designed to simplify the implementation of asynchronous data models. It provides tools to handle asynchronous operations, making it easier to work with modern Python applications that rely on async/await patterns.
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
- **Asynchronous Data Models**: Define and manage data models with full async support.
|
|
43
|
+
- **Ease of Use**: Simplified API for seamless integration into your projects.
|
|
44
|
+
- **Extensibility**: Easily extend and customize models to fit your needs.
|
|
45
|
+
- **Performance**: Optimized for high-performance asynchronous workflows.
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
Install the library using pip:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install finalsa-async-models
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
Here's a quick example of how to use Finalsa Async Models:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from finalsa_async_models import AsyncModel
|
|
61
|
+
|
|
62
|
+
class User(AsyncModel):
|
|
63
|
+
async def save(self):
|
|
64
|
+
# Custom save logic
|
|
65
|
+
pass
|
|
66
|
+
|
|
67
|
+
# Example usage
|
|
68
|
+
async def main():
|
|
69
|
+
user = User()
|
|
70
|
+
await user.save()
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Documentation
|
|
74
|
+
|
|
75
|
+
For detailed documentation, visit the [official documentation](#).
|
|
76
|
+
|
|
77
|
+
## Contributing
|
|
78
|
+
|
|
79
|
+
Contributions are welcome! Please follow the [contribution guidelines](CONTRIBUTING.md).
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
84
|
+
|
|
85
|
+
## Contact
|
|
86
|
+
|
|
87
|
+
For questions or support, please open an issue on the [GitHub repository](#).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
finalsa/common/models/__init__.py,sha256=dpbPa6l-MEYqNegIV813SZz2yKU8fI-kcmS8ZuSzQAs,234
|
|
2
|
+
finalsa/common/models/models/__init__.py,sha256=B3PmLZ4CUgrCIXNlBvfRMbfroiX1xgL4-TS-2D2-Tv8,237
|
|
3
|
+
finalsa/common/models/models/functions.py,sha256=4bA57p5ar0btRlygzzLIlImQxOTypH3EQUyzys-ryE8,1551
|
|
4
|
+
finalsa/common/models/models/meta.py,sha256=YX62zKeu_3McVJUhGDrub897XfuGxDDKGw5AejEL48g,213
|
|
5
|
+
finalsa/common/models/models/sqs_response.py,sha256=CIK02um2Cl8spIORbu7uZn6g6YkILvjcCN3OWTTF-xo,2216
|
|
6
|
+
finalsa_common_models-2.0.0.dist-info/METADATA,sha256=Z_p-YJewJdQtIaegzSdv70iSupiy-FxFAeiLGrchovs,3054
|
|
7
|
+
finalsa_common_models-2.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
+
finalsa_common_models-2.0.0.dist-info/licenses/LICENSE.md,sha256=yqzhfnTBr2S4lUBx-yibVPOIXRUDPrSUN9-_7AsC6OU,1084
|
|
9
|
+
finalsa_common_models-2.0.0.dist-info/RECORD,,
|
{finalsa_common_models-1.0.0.data/data → finalsa_common_models-2.0.0.dist-info/licenses}/LICENSE.md
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025 Luis Diego Jiménez Delgado
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
from datetime import datetime, timezone
|
|
2
|
-
from typing import Optional, Union, Dict
|
|
3
|
-
from uuid import UUID
|
|
4
|
-
from pydantic import BaseModel
|
|
5
|
-
from json import loads
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class SqsMessage(BaseModel):
|
|
9
|
-
id: UUID
|
|
10
|
-
topic: str
|
|
11
|
-
payload: Union[str, Dict]
|
|
12
|
-
correlation_id: str
|
|
13
|
-
timestamp: Optional[datetime] = datetime.now(timezone.utc)
|
|
14
|
-
|
|
15
|
-
def get_payload(self) -> Dict:
|
|
16
|
-
if isinstance(self.payload, str):
|
|
17
|
-
self.payload = loads(self.payload)
|
|
18
|
-
return self.payload
|
|
19
|
-
|
|
20
|
-
def to_dict(self):
|
|
21
|
-
return {
|
|
22
|
-
'id': str(self.id),
|
|
23
|
-
'topic': self.topic,
|
|
24
|
-
'payload': self.payload,
|
|
25
|
-
'correlation_id': self.correlation_id,
|
|
26
|
-
'timestamp': self.timestamp.isoformat()
|
|
27
|
-
}
|
finalsa/common/models/py.typed
DELETED
|
File without changes
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Luis Diego Jiménez Delgado
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: finalsa-common-models
|
|
3
|
-
Version: 1.0.0
|
|
4
|
-
Summary: An utils package for using finalsa common models.
|
|
5
|
-
Home-page: https://github.com/finalsa/finalsa-common-models
|
|
6
|
-
Author: Luis Jimenez
|
|
7
|
-
Author-email: luis@finalsa.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Keywords: dynamodb
|
|
10
|
-
Classifier: Intended Audience :: Developers
|
|
11
|
-
Classifier: License :: OSI Approved :: BSD License
|
|
12
|
-
Classifier: Operating System :: OS Independent
|
|
13
|
-
Classifier: Topic :: Internet :: WWW/HTTP
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
-
Requires-Python: >=3.10
|
|
20
|
-
Description-Content-Type: text/markdown
|
|
21
|
-
License-File: LICENSE.md
|
|
22
|
-
Requires-Dist: boto3 >=1.20.3
|
|
23
|
-
Requires-Dist: pydantic >=2.5.2
|
|
24
|
-
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
finalsa/common/models/__init__.py,sha256=XUFJBrRoyrVq-jL_qMTPGevjOLue8VRPKYnU9KcPauc,268
|
|
2
|
-
finalsa/common/models/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
finalsa/common/models/models/__init__.py,sha256=Bm0KxSyueMwLkiN4W3sX5oXgLbfyQ8ZhKPD0WLhZepA,144
|
|
4
|
-
finalsa/common/models/models/functions.py,sha256=4bA57p5ar0btRlygzzLIlImQxOTypH3EQUyzys-ryE8,1551
|
|
5
|
-
finalsa/common/models/models/sqs_message.py,sha256=0E2dx_Ml55rNn6dG7jMQH9jL28bLECiZDAgNprBGSpM,742
|
|
6
|
-
finalsa/common/models/models/sqs_response.py,sha256=ln16utWyTvd8mHWzdh7eOpVmIEuEbQfKb-sDHZTU0Oc,4257
|
|
7
|
-
finalsa_common_models-1.0.0.data/data/LICENSE.md,sha256=_lu-V-f2tGID1BS2V_W6D2XWppBsylFF1J2KEpfIXN0,1084
|
|
8
|
-
finalsa_common_models-1.0.0.dist-info/LICENSE.md,sha256=_lu-V-f2tGID1BS2V_W6D2XWppBsylFF1J2KEpfIXN0,1084
|
|
9
|
-
finalsa_common_models-1.0.0.dist-info/METADATA,sha256=HmjP2g7G9X-wluTx6V6Azr-8hnrS6uRXjPjXQC_-WRU,853
|
|
10
|
-
finalsa_common_models-1.0.0.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
|
11
|
-
finalsa_common_models-1.0.0.dist-info/top_level.txt,sha256=P7YD1HSd4CVujGFG9Vl9hJlg5OVCGN2J_ZsSQezWZAs,51
|
|
12
|
-
finalsa_common_models-1.0.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
13
|
-
finalsa_common_models-1.0.0.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|