Responses

Response headers

class elastic_transport.HttpHeaders(initial=None)

HTTP headers

Behaves like a Python dictionary. Can be used like this:

headers = HttpHeaders()
headers["foo"] = "bar"
headers["foo"] = "baz"
print(headers["foo"])  # prints "baz"
freeze()

Freezes the current set of headers so they can be used in hashes. Returns the same instance, doesn’t make a copy.

Return type:

HttpHeaders

Metadata

class elastic_transport.ApiResponseMeta(status, http_version, headers, duration, node)

Metadata that is returned from Transport.perform_request()

Variables:
  • status (int) – HTTP status code

  • http_version (str) – HTTP version being used

  • headers (HttpHeaders) – HTTP headers

  • duration (float) – Number of seconds from start of request to start of response

  • node (NodeConfig) – Node which handled the request

  • mimetype (Optional[str]) – Mimetype to be used by the serializer to decode the raw response bytes.

Response classes

class elastic_transport.ApiResponse(*args, **kwargs)

Base class for all API response classes

property body: _BodyType

User-friendly view into the raw response with type hints if applicable

property meta: ApiResponseMeta

Response metadata

class elastic_transport.BinaryApiResponse(*args, **kwargs)

Bases: ApiResponse[bytes]

API responses which are a binary response such as Mapbox vector tiles

property body: bytes

User-friendly view into the raw response with type hints if applicable

class elastic_transport.HeadApiResponse(meta)

Bases: ApiResponse[bool]

API responses which are for an ‘exists’ / HEAD API request

property body: bool

User-friendly view into the raw response with type hints if applicable

class elastic_transport.ListApiResponse(*args, **kwargs)

Bases: Generic[_ListItemBodyType], ApiResponse[List[Any]]

API responses which are a list of items. Can be NDJSON or a JSON list

property body: List[_ListItemBodyType]

User-friendly view into the raw response with type hints if applicable

class elastic_transport.ObjectApiResponse(*args, **kwargs)

Bases: Generic[_ObjectBodyType], ApiResponse[Dict[str, Any]]

API responses which are for a JSON object

property body: _ObjectBodyType

User-friendly view into the raw response with type hints if applicable

class elastic_transport.TextApiResponse(*args, **kwargs)

Bases: ApiResponse[str]

API responses which are text such as ‘text/plain’ or ‘text/csv’

property body: str

User-friendly view into the raw response with type hints if applicable