MCPcopy Index your code
hub / github.com/StackStorm/st2 / parse_api_response

Function parse_api_response

st2client/st2client/models/core.py:50–69  ·  view source on GitHub ↗

Utility function which parses API json response using orjson. requests uses simplejson, but this version uses orjson which can be up to 50% faster and that is especially pronounced with larger response.

(response: requests.models.Response)

Source from the content-addressed store, hash-verified

48
49
50def parse_api_response(response: requests.models.Response) -> dict:
51 """
52 Utility function which parses API json response using orjson.
53
54 requests uses simplejson, but this version uses orjson which can be up to 50% faster and that
55 is especially pronounced with larger response.
56 """
57 # Upstream implementation is available at
58 # https://github.com/psf/requests/blob/master/requests/models.py#L876
59 # NOTE: It's important that we manually decode response.content attribute before passing it to
60 # orjson otherwise orjson will try to decode it and will be slower.
61
62 # Inside tests content is not always bytes
63 if isinstance(response.content, str):
64 data = response.content
65 else:
66 data = response.content.decode("utf-8")
67
68 data = orjson.loads(data)
69 return data
70
71
72class Resource(object):

Callers 15

handle_errorMethod · 0.85
get_allMethod · 0.85
get_by_idMethod · 0.85
get_propertyMethod · 0.85
_query_detailsMethod · 0.85
createMethod · 0.85
updateMethod · 0.85
cloneMethod · 0.85
delete_by_idMethod · 0.85
matchMethod · 0.85
match_and_executeMethod · 0.85
re_runMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected