Tools for handling appsync responses and routes.
Project description
appsync-tools
##Provides helpful tools for parsing database responses and handling routes inside of Lambda for AWS Appsync.
DB response parsing
Aurora results are returned as a list of dictionaries with the column names being the key. Nulls (returned by Aurora as isNull) are returned as None types. Any value that can be parsed as json is cast from a string to a list/dictionary. Responses are returned formated as:
[
{"columnOneName": "value", "columnTwoName": "value"},
{"columnOneName": "value", "columnTwoName": "value"}
]
Where each item in the top level array is a separate row.
Dynamodb results are returned as either a dictionary (for get_item operations) or a list of dictionaries (query).
Pretty parsing Aurora records
pretty_parse_aurora(records, type_attribute=None) -> list
Arguments:
- records -- The records from the API query (execute_statement()["records"])
Keyword Args:
- type_attribute -- If used will pass results to typify(results, type_attribute=type_attribute) before returning
from appsync_tools import pretty_parse_aurora
response = client.execute_statement(
secretArn=environ["PG_SECRET"],
database=environ["DB_NAME"],
parameters=parameters,
resourceArn=environ["DB_ARN"],
includeResultMetadata=True,
sql=sql
)
print(pretty_parse_aurora(response))
Parsing Dynamodb records
pretty_parse_dynamo(records, type_attribute=None) -> list | dict
Arguments:
- records -- The Item(s) from a call to query, get_item
Keyword Args:
- type_attribute -- If used will pass results to typify(results, type_attribute=type_attribute) before returning
from appsync_tools import pretty_parse_dynamo
response = client.get_item(
Key={"pk": "foo", "sk": "bar"}
)
print(response.get("Item"))
Adding __typename to all records based on an attribute
typify(records, type_attribute="type") -> list | dict Arguments:
- records -- The Item(s) from a call to query, get_item
Keyword Args:
- type_attribute -- Attribute name that contains the __typename value
Example
from appsync_tools import typify
response = client.get_item(
Key={"pk": "foo", "sk": "BarType"}
)
print(typify(response.get("Item"), type_attribute="sk"))
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file appsync-tools-2.0.5.tar.gz
.
File metadata
- Download URL: appsync-tools-2.0.5.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e7198336f57b2bba640a40b9961887f926cc4c8c5dcd25606a972dcce8035f4 |
|
MD5 | 0765150184f0b3b23dc9e439fde68306 |
|
BLAKE2b-256 | faa0f1ff5d8a2ed311a7144edb80a3380b9280a7f4eb71be832fb84c77cd6a3c |
File details
Details for the file appsync_tools-2.0.5-py2.py3-none-any.whl
.
File metadata
- Download URL: appsync_tools-2.0.5-py2.py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af1bf3fcec87a3c9c96da4fd8caa9a164899fdd5b236e50aa5bd358da85d6cd9 |
|
MD5 | e2df1c149218697f0e7988606ca8fed1 |
|
BLAKE2b-256 | 919b34b6eb4eabce9ef221fa725a7cc27eb776cba399cfeba9aa24b020094f36 |