pygrestqlambda 0.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.
- pygrestqlambda/__init__.py +0 -0
- pygrestqlambda/aws/lambda_function/json_transform.py +18 -0
- pygrestqlambda/aws/lambda_function/proxy_integration_respose.py +54 -0
- pygrestqlambda/db/record.py +66 -0
- pygrestqlambda-0.0.0.dist-info/METADATA +34 -0
- pygrestqlambda-0.0.0.dist-info/RECORD +8 -0
- pygrestqlambda-0.0.0.dist-info/WHEEL +4 -0
- pygrestqlambda-0.0.0.dist-info/licenses/LICENSE +21 -0
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
from uuid import UUID
|
2
|
+
from datetime import datetime
|
3
|
+
|
4
|
+
|
5
|
+
def json_output(value: object) -> str:
|
6
|
+
"""
|
7
|
+
Calculates the serialised version of an object to return in a JSON response
|
8
|
+
"""
|
9
|
+
|
10
|
+
# Handle UUIDs
|
11
|
+
if isinstance(value, UUID):
|
12
|
+
value = str(value)
|
13
|
+
|
14
|
+
# Handle timestamps
|
15
|
+
if isinstance(value, datetime):
|
16
|
+
value = value.isoformat()
|
17
|
+
|
18
|
+
return value
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"""
|
2
|
+
Receives payload in format sent by AWS REST API Gateway
|
3
|
+
https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
|
4
|
+
|
5
|
+
Returns payload structure expected by REST API Gateway
|
6
|
+
https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format
|
7
|
+
"""
|
8
|
+
|
9
|
+
import logging
|
10
|
+
import json
|
11
|
+
from dataclasses import dataclass
|
12
|
+
from pygrestqlambda.aws.lambda_function.json_transform import json_output
|
13
|
+
from base64 import b64encode
|
14
|
+
|
15
|
+
|
16
|
+
@dataclass
|
17
|
+
class LambdaFunctionProxyIntegrationResponse:
|
18
|
+
"""
|
19
|
+
Lambda function response
|
20
|
+
"""
|
21
|
+
is_base64_encoded: bool | None = False
|
22
|
+
status_code: int | None = 401
|
23
|
+
headers: dict | None = None
|
24
|
+
multi_value_headers: dict | None = None
|
25
|
+
body: str | None = None
|
26
|
+
|
27
|
+
def get_payload(self) -> dict:
|
28
|
+
"""
|
29
|
+
Gets payload to send to REST API Gateway
|
30
|
+
"""
|
31
|
+
|
32
|
+
# Set headers
|
33
|
+
if self.headers is None:
|
34
|
+
self.headers = {}
|
35
|
+
|
36
|
+
if "Content-Type" not in self.headers:
|
37
|
+
self.headers["Content-Type"] = "application/json"
|
38
|
+
|
39
|
+
# Calculate body
|
40
|
+
if self.is_base64_encoded:
|
41
|
+
body = b64encode(self.body).decode("utf-8")
|
42
|
+
else:
|
43
|
+
body = json.dumps(self.body, default=json_output)
|
44
|
+
|
45
|
+
logging.debug("Transforming dataclass dictionary to JSON")
|
46
|
+
data = {
|
47
|
+
"isBase64Encoded": self.is_base64_encoded,
|
48
|
+
"statusCode": self.status_code,
|
49
|
+
"headers": self.headers,
|
50
|
+
"multiValueHeaders": self.multi_value_headers,
|
51
|
+
"body": body,
|
52
|
+
}
|
53
|
+
|
54
|
+
return data
|
@@ -0,0 +1,66 @@
|
|
1
|
+
from abc import ABCMeta
|
2
|
+
|
3
|
+
|
4
|
+
class Record(metaclass=ABCMeta):
|
5
|
+
"""
|
6
|
+
Generic record that maps to a row in a database table
|
7
|
+
"""
|
8
|
+
|
9
|
+
def __init__(self, conn: bool = False) -> None:
|
10
|
+
self.conn = conn
|
11
|
+
|
12
|
+
def before_create(self):
|
13
|
+
"""
|
14
|
+
Runs before a new record is created. Useful for mutating a new record
|
15
|
+
before being committed.
|
16
|
+
"""
|
17
|
+
pass
|
18
|
+
|
19
|
+
def before_read(self):
|
20
|
+
"""
|
21
|
+
Before a record is retrieved from the database. Useful for injecting
|
22
|
+
filters or sorting.
|
23
|
+
"""
|
24
|
+
pass
|
25
|
+
|
26
|
+
def before_update(self):
|
27
|
+
"""
|
28
|
+
Before a new record is created. Useful for mutating a record before it
|
29
|
+
is committed.
|
30
|
+
"""
|
31
|
+
pass
|
32
|
+
|
33
|
+
def before_delete(self):
|
34
|
+
"""
|
35
|
+
Before an existing record is deleted. Useful for e.g. updating counters
|
36
|
+
or other aggregate fields in other tables.
|
37
|
+
"""
|
38
|
+
pass
|
39
|
+
|
40
|
+
def after_create(self):
|
41
|
+
"""
|
42
|
+
Runs after a new record is created. Useful for updating e.g. counters
|
43
|
+
tables.
|
44
|
+
"""
|
45
|
+
pass
|
46
|
+
|
47
|
+
def after_read(self):
|
48
|
+
"""
|
49
|
+
After a record is retrieved from the database. Useful for transforming
|
50
|
+
retrieved data.
|
51
|
+
"""
|
52
|
+
pass
|
53
|
+
|
54
|
+
def after_update(self):
|
55
|
+
"""
|
56
|
+
Runs after a new record is updated. Useful for updating e.g. counters
|
57
|
+
tables.
|
58
|
+
"""
|
59
|
+
pass
|
60
|
+
|
61
|
+
def after_delete(self):
|
62
|
+
"""
|
63
|
+
Runs after an existing record is deleted. Useful for updating e.g.
|
64
|
+
counters tables.
|
65
|
+
"""
|
66
|
+
pass
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: pygrestqlambda
|
3
|
+
Version: 0.0.0
|
4
|
+
Summary: PostgreSQL REST API framework for AWS Lambda functions
|
5
|
+
Project-URL: Homepage, https://github.com/mesogate/pygrestqlambda
|
6
|
+
Project-URL: Issues, https://github.com/mesogate/pygrestqlambda/issues
|
7
|
+
Author-email: Voquis Limited <opensource@voquis.com>
|
8
|
+
License-File: LICENSE
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
12
|
+
Requires-Python: >=3.11
|
13
|
+
Requires-Dist: aws-xray-sdk
|
14
|
+
Requires-Dist: boto3
|
15
|
+
Provides-Extra: dev
|
16
|
+
Requires-Dist: build; extra == 'dev'
|
17
|
+
Requires-Dist: pylint; extra == 'dev'
|
18
|
+
Requires-Dist: pytest; extra == 'dev'
|
19
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
20
|
+
Requires-Dist: ruff; extra == 'dev'
|
21
|
+
Requires-Dist: twine; extra == 'dev'
|
22
|
+
Description-Content-Type: text/markdown
|
23
|
+
|
24
|
+
# Python PostgreSQL REST API framework for AWS Lambda functions
|
25
|
+
> [!NOTE]
|
26
|
+
> Project status: `Alpha`
|
27
|
+
|
28
|
+
A REST API web framework for persisting records in a PostgreSQL database.
|
29
|
+
|
30
|
+
## Supported features
|
31
|
+
- Automatic creation of `uid` fields
|
32
|
+
- Automatic setting of `created_at` and `last_updated_at` timestamps
|
33
|
+
- Automatic setting of `creator_uid` and `last_updater_uid`
|
34
|
+
- RDS with IAM credentials
|
@@ -0,0 +1,8 @@
|
|
1
|
+
pygrestqlambda/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
pygrestqlambda/aws/lambda_function/json_transform.py,sha256=Jye6MxYb1vyU4Bz4aLIcYauMwAHrMCZPdUlF3AqdJTM,381
|
3
|
+
pygrestqlambda/aws/lambda_function/proxy_integration_respose.py,sha256=TMnOk0RMFaDhbFk5ZAfCVQmN_mMKX5KpgKKxwisKV8I,1702
|
4
|
+
pygrestqlambda/db/record.py,sha256=EoPJTWNfF2ieEV7if2neieF0VZsf2Fs44SW13h3fZcA,1577
|
5
|
+
pygrestqlambda-0.0.0.dist-info/METADATA,sha256=t1_x_ZXzWSBxXfobwAZCxQ2C7Y_sB1fEtTTHiteqBUk,1233
|
6
|
+
pygrestqlambda-0.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
+
pygrestqlambda-0.0.0.dist-info/licenses/LICENSE,sha256=8QeS1c5uv4AYoEG3M80OSCBuC_Pk-6vjU1VBUnlX2m0,1071
|
8
|
+
pygrestqlambda-0.0.0.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Voquis Limited
|
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.
|