Skip to content
Back to top
View this page

# 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: Tuple[str, int] | None

    Host and port of the Elasticsearch instance

  kibana_address: Tuple[str, int] | None

    Host and port of the Kibana instance

class elastic_transport.client_utils.DefaultType(*values)

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

elastic_transport.client_utils.basic_auth_to_header(basic_auth)

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

  Return type:

    `str`

elastic_transport.client_utils.client_meta_version(version)

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

  Return type:

    `str`

elastic_transport.client_utils.create_user_agent(name, version)

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

  Return type:

    `str`

elastic_transport.client_utils.parse_cloud_id(cloud_id)

  Parses an Elastic Cloud ID into its components

  Return type:

    `CloudId`

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:

    `str`

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:

    `TypeVar`(`T`)

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.

  Parameters:

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

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

  Return type:

    `NodeConfig`