Transport#

class elastic_transport.Transport(node_configs, node_class=<class 'elastic_transport.Urllib3HttpNode'>, node_pool_class=<class 'elastic_transport.NodePool'>, randomize_nodes_in_pool=True, node_selector_class=None, dead_node_backoff_factor=None, max_dead_node_backoff=None, serializers=None, default_mimetype='application/json', max_retries=3, retry_on_status=(429, 502, 503, 504), retry_on_timeout=False, sniff_on_start=False, sniff_before_requests=False, sniff_on_node_failure=False, sniff_timeout=0.5, min_delay_between_sniffing=10.0, sniff_callback=None, meta_header=True, client_meta_service=('et', '8.13.0'))#

Encapsulation of transport-related to logic. Handles instantiation of the individual nodes as well as creating a node pool to hold them.

Main interface is the elastic_transport.Transport.perform_request() method.

close()#

Explicitly closes all nodes in the transport’s pool

Return type:

None

perform_request(method, target, *, body=None, headers=DefaultType.value, max_retries=DefaultType.value, retry_on_status=DefaultType.value, retry_on_timeout=DefaultType.value, request_timeout=DefaultType.value, client_meta=DefaultType.value, otel_span=DefaultType.value)#

Perform the actual request. Retrieve a node from the node pool, pass all the information to it’s perform_request method and return the data.

If an exception was raised, mark the node as failed and retry (up to max_retries times).

If the operation was successful and the node used was previously marked as dead, mark it as live, resetting it’s failure count.

Parameters:
  • method (str) – HTTP method to use

  • target (str) – HTTP request target

  • body (Optional[Any]) – body of the request, will be serialized using serializer and passed to the node

  • headers (Union[Mapping[str, Any], DefaultType]) – Additional headers to send with the request.

  • max_retries (Union[int, DefaultType]) – Maximum number of retries before giving up on a request. Set to 0 to disable retries.

  • retry_on_status (Union[Collection[int], DefaultType]) – Collection of HTTP status codes to retry.

  • retry_on_timeout (Union[bool, DefaultType]) – Set to true to retry after timeout errors.

  • request_timeout (Union[float, None, DefaultType]) – Amount of time to wait for a response to fail with a timeout error.

  • client_meta (Union[Tuple[Tuple[str, str], ...], DefaultType]) – Extra client metadata key-value pairs to send in the client meta header.

  • otel_span (Union[OpenTelemetrySpan, DefaultType]) – OpenTelemetry span used to add metadata to the span.

Return type:

TransportApiResponse

Returns:

Tuple of the elastic_transport.ApiResponseMeta with the deserialized response.

class elastic_transport.AsyncTransport(node_configs, node_class=<class 'elastic_transport.AiohttpHttpNode'>, node_pool_class=<class 'elastic_transport.NodePool'>, randomize_nodes_in_pool=True, node_selector_class=None, dead_node_backoff_factor=None, max_dead_node_backoff=None, serializers=None, default_mimetype='application/json', max_retries=3, retry_on_status=(429, 502, 503, 504), retry_on_timeout=False, sniff_on_start=False, sniff_before_requests=False, sniff_on_node_failure=False, sniff_timeout=0.5, min_delay_between_sniffing=10.0, sniff_callback=None, meta_header=True, client_meta_service=('et', '8.13.0'))#

Encapsulation of transport-related to logic. Handles instantiation of the individual nodes as well as creating a node pool to hold them.

Main interface is the elastic_transport.Transport.perform_request() method.

async close()#

Explicitly closes all nodes in the transport’s pool

Return type:

None

async perform_request(method, target, *, body=None, headers=DefaultType.value, max_retries=DefaultType.value, retry_on_status=DefaultType.value, retry_on_timeout=DefaultType.value, request_timeout=DefaultType.value, client_meta=DefaultType.value, otel_span=DefaultType.value)#

Perform the actual request. Retrieve a node from the node pool, pass all the information to it’s perform_request method and return the data.

If an exception was raised, mark the node as failed and retry (up to max_retries times).

If the operation was successful and the node used was previously marked as dead, mark it as live, resetting it’s failure count.

Parameters:
  • method (str) – HTTP method to use

  • target (str) – HTTP request target

  • body (Optional[Any]) – body of the request, will be serialized using serializer and passed to the node

  • headers (Union[Mapping[str, Any], DefaultType]) – Additional headers to send with the request.

  • max_retries (Union[int, DefaultType]) – Maximum number of retries before giving up on a request. Set to 0 to disable retries.

  • retry_on_status (Union[Collection[int], DefaultType]) – Collection of HTTP status codes to retry.

  • retry_on_timeout (Union[bool, DefaultType]) – Set to true to retry after timeout errors.

  • request_timeout (Union[float, None, DefaultType]) – Amount of time to wait for a response to fail with a timeout error.

  • client_meta (Union[Tuple[Tuple[str, str], ...], DefaultType]) – Extra client metadata key-value pairs to send in the client meta header.

  • otel_span (Union[OpenTelemetrySpan, DefaultType]) – OpenTelemetry span used to add metadata to the span.

Return type:

TransportApiResponse

Returns:

Tuple of the elastic_transport.ApiResponseMeta with the deserialized response.