Closed
Description
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.
from elasticsearch import Elasticsearch
client = 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.hits
HitsMetadata(hits=[...], ...)
# Can access transport information from the response
>>> resp.meta
ApiResponseMeta(
status=200,
headers={
...
}
)
Non-JSON Responses
Responses which aren't JSON will still be wrapped as objects:
resp = client.cat.tasks()
>>> resp
"..."
>>> resp.raw
"..."