connection

class opensearchpy.Connection(host='localhost', port=None, use_ssl=False, url_prefix='', timeout=10, headers=None, http_compress=None, opaque_id=None, **kwargs)[source]

Bases: object

Class responsible for maintaining a connection to an OpenSearch node. It holds persistent connection pool to it and its main interface (perform_request) is thread-safe.

Also responsible for logging.

Parameters:
  • host (str) – hostname of the node (default: localhost)

  • port (int | None) – port to use (integer, default: 9200)

  • use_ssl (bool) – use ssl for the connection if True

  • url_prefix (str) – optional url prefix for opensearch

  • timeout (int) – default timeout in seconds (float, default: 10)

  • http_compress (bool | None) – Use gzip compression

  • opaque_id (str | None) – Send this value in the ‘X-Opaque-Id’ HTTP header For tracing all requests made by this transport.

  • host

  • port

  • use_ssl

  • url_prefix

  • timeout

  • headers (Dict[str, str] | None) –

  • http_compress

  • opaque_id

  • kwargs (Any) –

__eq__(other)[source]

Return self==value.

Parameters:

other (object) –

Return type:

bool

__hash__()[source]

Return hash(self).

Return type:

int

__lt__(other)[source]

Return self<value.

Parameters:

other (object) –

Return type:

bool

__repr__()[source]

Return repr(self).

Return type:

str

_raise_error(status_code, raw_data, content_type=None)[source]

Locate appropriate exception and raise it.

Parameters:
  • status_code (int) –

  • raw_data (str | bytes) –

  • content_type (str | None) –

Return type:

None

_raise_warnings(warning_headers)[source]

If ‘headers’ contains a ‘Warning’ header raise the warnings to be seen by the user. Takes an iterable of string values from any number of ‘Warning’ headers.

Parameters:

warning_headers (Any) –

Return type:

None

static default_ca_certs()[source]

Get the default CA certificate bundle, preferring those configured in the standard OpenSSL environment variables before those provided by certifi (if available)

Return type:

str | None

log_request_fail(method, full_url, path, body, duration, status_code=None, response=None, exception=None)[source]

Log an unsuccessful API call.

Parameters:
  • method (str) –

  • full_url (str) –

  • path (str) –

  • body (Any) –

  • duration (float) –

  • status_code (int | None) –

  • response (str | None) –

  • exception (Exception | None) –

Return type:

None

log_request_success(method, full_url, path, body, status_code, response, duration)[source]

Log a successful API call.

Parameters:
  • method (str) –

  • full_url (str) –

  • path (str) –

  • body (Any) –

  • status_code (int) –

  • response (str) –

  • duration (float) –

Return type:

None

class opensearchpy.RequestsHttpConnection(host='localhost', port=None, http_auth=None, use_ssl=False, verify_certs=True, ssl_show_warn=True, ca_certs=None, client_cert=None, client_key=None, headers=None, http_compress=None, opaque_id=None, pool_maxsize=None, metrics=<opensearchpy.metrics.metrics_none.MetricsNone object>, **kwargs)[source]

Bases: Connection

Connection using the requests library.

Parameters:
  • http_auth (Any) – optional http auth information as either ‘:’ separated string or a tuple. Any value will be passed into requests as auth.

  • use_ssl (bool) – use ssl for the connection if True

  • verify_certs (bool) – whether to verify SSL certificates

  • ssl_show_warn (bool) – show warning when verify certs is disabled

  • ca_certs (Any) – optional path to CA bundle. Defaults to configured OpenSSL bundles from environment variables and then certifi before falling back to the standard requests bundle to improve consistency with other Connection implementations

  • client_cert (Any) – path to the file containing the private key and the certificate, or cert only if using client_key

  • client_key (Any) – path to the file containing the private key if using separate cert and key files (client_cert will contain only the cert)

  • headers (Any) – any custom http headers to be add to requests

  • http_compress (Any) – Use gzip compression

  • opaque_id (Any) – Send this value in the ‘X-Opaque-Id’ HTTP header For tracing all requests made by this transport.

  • pool_maxsize (Any) – Maximum connection pool size used by pool-manager For custom connection-pooling on current session

  • metrics (Metrics) – metrics is an instance of a subclass of the Metrics class, used for collecting and reporting metrics related to the client’s operations;

  • host (str) –

  • port (int | None) –

  • http_auth

  • use_ssl

  • verify_certs

  • ssl_show_warn

  • ca_certs

  • client_cert

  • client_key

  • headers

  • http_compress

  • opaque_id

  • pool_maxsize

  • metrics

  • kwargs (Any) –

close()[source]

Explicitly closes connections

Return type:

None

class opensearchpy.Urllib3HttpConnection(host='localhost', port=None, http_auth=None, use_ssl=False, verify_certs=<object object>, ssl_show_warn=<object object>, ca_certs=None, client_cert=None, client_key=None, ssl_version=None, ssl_assert_hostname=None, ssl_assert_fingerprint=None, pool_maxsize=None, headers=None, ssl_context=None, http_compress=None, opaque_id=None, metrics=<opensearchpy.metrics.metrics_none.MetricsNone object>, **kwargs)[source]

Bases: Connection

Default connection class using the urllib3 library and the http protocol.

Parameters:
  • host (str) – hostname of the node (default: localhost)

  • port (int | None) – port to use (integer, default: 9200)

  • url_prefix – optional url prefix for opensearch

  • timeout – default timeout in seconds (float, default: 10)

  • http_auth (Any) – optional http auth information as either ‘:’ separated string or a tuple

  • use_ssl (bool) – use ssl for the connection if True

  • verify_certs (Any) – whether to verify SSL certificates

  • ssl_show_warn (Any) – show warning when verify certs is disabled

  • ca_certs (Any) – optional path to CA bundle. See https://urllib3.readthedocs.io/en/latest/security.html#using-certifi-with-urllib3 for instructions how to get default set

  • client_cert (Any) – path to the file containing the private key and the certificate, or cert only if using client_key

  • client_key (Any) – path to the file containing the private key if using separate cert and key files (client_cert will contain only the cert)

  • ssl_version (Any) – version of the SSL protocol to use. Choices are: SSLv23 (default) SSLv2 SSLv3 TLSv1 (see PROTOCOL_* constants in the ssl module for exact options for your environment).

  • ssl_assert_hostname (Any) – use hostname verification if not False

  • ssl_assert_fingerprint (Any) – verify the supplied certificate fingerprint if not None

  • pool_maxsize (Any) – the number of connections which will be kept open to this host. See https://urllib3.readthedocs.io/en/1.4/pools.html#api for more information.

  • headers (Any) – any custom http headers to be add to requests

  • http_compress (Any) – Use gzip compression

  • opaque_id (Any) – Send this value in the ‘X-Opaque-Id’ HTTP header For tracing all requests made by this transport.

  • metrics (Metrics) – metrics is an instance of a subclass of the Metrics class, used for collecting and reporting metrics related to the client’s operations;

  • host

  • port

  • http_auth

  • use_ssl

  • verify_certs

  • ssl_show_warn

  • ca_certs

  • client_cert

  • client_key

  • ssl_version

  • ssl_assert_hostname

  • ssl_assert_fingerprint

  • pool_maxsize

  • headers

  • ssl_context (Any) –

  • http_compress

  • opaque_id

  • metrics

  • kwargs (Any) –

close()[source]

Explicitly closes connection

Return type:

None

opensearchpy.connections

alias of <module ‘opensearchpy.connection.connections’ from ‘/home/runner/work/opensearch-py/opensearch-py/.nox/docs/lib/python3.8/site-packages/opensearchpy/connection/connections.py’>