Nodes#

Configuring nodes#

class elastic_transport.NodeConfig(scheme, host, port, path_prefix='', headers=<factory>, connections_per_node=10, request_timeout=10.0, http_compress=False, verify_certs=True, ca_certs=None, client_cert=None, client_key=None, ssl_assert_hostname=None, ssl_assert_fingerprint=None, ssl_version=None, ssl_context=None, ssl_show_warn=True, _extras=<factory>)#

Configuration options available for every node.

Node classes#

class elastic_transport.Urllib3HttpNode(config)#

Default synchronous node class using the urllib3 library via HTTP

close()#

Explicitly closes connection

Return type

None

perform_request(method, target, body=None, headers=None, request_timeout=DefaultType.value)#

Constructs and sends an HTTP request and parses the HTTP response.

Parameters
  • method (str) – HTTP method

  • target (str) – HTTP request target, typically path+query

  • body (Optional[bytes]) – Optional HTTP request body encoded as bytes

  • headers (Optional[HttpHeaders]) – Optional HTTP headers to send in addition to the headers already configured.

  • request_timeout (Union[DefaultType, float, None]) – Amount of time to wait for the first response bytes to arrive before raising a elastic_transport.ConnectionTimeout error.

Raises

elastic_transport.ConnectionError, elastic_transport.ConnectionTimeout, elastic_transport.TlsError

Return type

Tuple[ApiResponseMeta, bytes]

Returns

Metadata about the request+response and the raw decompressed bytes from the HTTP response body.

class elastic_transport.RequestsHttpNode(config)#

Synchronous node using the requests library communicating via HTTP.

Supports setting requests.Session.auth via the elastic_transport.NodeConfig._extras using the requests.session.auth key.

close()#

Explicitly closes connections

Return type

None

perform_request(method, target, body=None, headers=None, request_timeout=DefaultType.value)#

Constructs and sends an HTTP request and parses the HTTP response.

Parameters
  • method (str) – HTTP method

  • target (str) – HTTP request target, typically path+query

  • body (Optional[bytes]) – Optional HTTP request body encoded as bytes

  • headers (Optional[HttpHeaders]) – Optional HTTP headers to send in addition to the headers already configured.

  • request_timeout (Union[DefaultType, float, None]) – Amount of time to wait for the first response bytes to arrive before raising a elastic_transport.ConnectionTimeout error.

Raises

elastic_transport.ConnectionError, elastic_transport.ConnectionTimeout, elastic_transport.TlsError

Return type

Tuple[ApiResponseMeta, bytes]

Returns

Metadata about the request+response and the raw decompressed bytes from the HTTP response body.

class elastic_transport.AiohttpHttpNode(config)#

Default asynchronous node class using the aiohttp library via HTTP

async perform_request(method, target, body=None, headers=None, request_timeout=DefaultType.value)#

Constructs and sends an HTTP request and parses the HTTP response.

Parameters
  • method (str) – HTTP method

  • target (str) – HTTP request target, typically path+query

  • body (Optional[bytes]) – Optional HTTP request body encoded as bytes

  • headers (Optional[HttpHeaders]) – Optional HTTP headers to send in addition to the headers already configured.

  • request_timeout (Union[DefaultType, float, None]) – Amount of time to wait for the first response bytes to arrive before raising a elastic_transport.ConnectionTimeout error.

Raises

elastic_transport.ConnectionError, elastic_transport.ConnectionTimeout, elastic_transport.TlsError

Return type

Tuple[ApiResponseMeta, bytes]

Returns

Metadata about the request+response and the raw decompressed bytes from the HTTP response body.

Custom node classes#

You can define your own node class like so:

from typing import Optional
from elastic_transport import Urllib3HttpNode, NodeConfig, ApiResponseMeta, HttpHeaders
from elastic_transport.client_utils import DefaultType, DEFAULT

class CustomHttpNode(Urllib3HttpNode):
   def perform_request(
      self,
      method: str,
      target: str,
      body: Optional[bytes] = None,
      headers: Optional[HttpHeaders] = None,
      request_timeout: Union[DefaultType, Optional[float]] = DEFAULT,
   ) -> Tuple[ApiResponseMeta, bytes]:
      # Define your HTTP request method here...

and once you have a custom node class you can pass the class to elastic_transport.Transport or an API client like so:

# Example using a Transport instance:
from elastic_transport import Transport

transport = Transport(..., node_class=CustomHttpNode)

# Example using an API client:
from elasticsearch import Elasticsearch

client = Elasticsearch(..., node_class=CustomHttpNode)