You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently APIs return dictionaries for JSON response bodies however this makes it impossible to determine transport-level information per-response and makes adding type hints not possible for more complex responses.
fromelasticsearchimportElasticsearchclient=Elasticsearch()
resp=client.search(
index="index",
query={"match_all": {}}
)
# Returns an API response instead of a dict>>>resp
{"hits": {"hits": [...], ...}, ...}
# Still access the response like a dict>>>resp["hits"]
{"hits": [...], ...}
# But also can access like an object>>>resp.body.hitsHitsMetadata(hits=[...], ...)
# Can access transport information from the response>>>resp.metaApiResponseMeta(
status=200,
headers={
...
}
)
Non-JSON Responses
Responses which aren't JSON will still be wrapped as objects:
sethmlarson
changed the title
Make API JSON responses accessible like objects with type hints
API responses accessible like objects with type hints
Aug 26, 2021
Currently APIs return dictionaries for JSON response bodies however this makes it impossible to determine transport-level information per-response and makes adding type hints not possible for more complex responses.
Non-JSON Responses
Responses which aren't JSON will still be wrapped as objects:
The text was updated successfully, but these errors were encountered: