Client Utilities

Reusable utilities for creating API clients using elastic_transport.

class elastic_transport.client_utils.CloudId(cluster_name, es_address, kibana_address)
cluster_name: str

Name of the cluster in Elastic Cloud

es_address: Optional[Tuple[str, int]]

Host and port of the Elasticsearch instance

kibana_address: Optional[Tuple[str, int]]

Host and port of the Kibana instance

class elastic_transport.client_utils.DefaultType(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Sentinel used as a default value when None has special meaning like timeouts. The only comparisons that are supported for this type are is.


Converts a 2-tuple into a ‘Basic’ HTTP Authorization header

Return type:



Converts a Python version into a version string compatible with the X-Elastic-Client-Meta HTTP header.

Return type:


elastic_transport.client_utils.create_user_agent(name, version)

Creates the ‘User-Agent’ header given the library name and version

Return type:



Parses an Elastic Cloud ID into its components

Return type:


elastic_transport.client_utils.percent_encode(string, safe='/', encoding=None, errors=None)

Percent-encodes a string so it can be used in an HTTP request target

Return type:


elastic_transport.client_utils.resolve_default(val, default)

Resolves a value that could be the DEFAULT sentinel into either the given value or the default value.

Return type:


elastic_transport.client_utils.url_to_node_config(url, use_default_ports_for_scheme=False)

Constructs a elastic_transport.NodeConfig instance from a URL. If a username/password are specified in the URL they are converted to an ‘Authorization’ header. Always fills in a default port for HTTPS.

  • url (str) – URL to transform into a NodeConfig.

  • use_default_ports_for_scheme (bool) – If ‘True’ will resolve default ports for HTTP.

Return type: