weaviate.connect

Module communication to a Weaviate instance. Used to connect to Weaviate and run REST requests.

class weaviate.connect.Connection(url: str, auth_client_secret: AuthBearerToken | AuthClientPassword | AuthClientCredentials | AuthApiKey | None, timeout_config: Tuple[int | float, int | float], proxies: dict | str | None, trust_env: bool, additional_headers: Dict[str, Any] | None, startup_period: int | None, connection_config: ConnectionConfig, embedded_db: EmbeddedDB | None = None, grcp_port: int | None = None)

Bases: object

Connection class used to communicate to a weaviate instance.

Initialize a Connection class instance.

Parameters:
  • url (str) – URL to a running weaviate instance.

  • auth_client_secret (weaviate.auth.AuthCredentials, optional) – Credentials to authenticate with a weaviate instance. The credentials are not saved within the client and authentication is done via authentication tokens.

  • timeout_config (tuple(float, float) or float, optional) – Set the timeout configuration for all requests to the Weaviate server. It can be a float or, a tuple of two floats: (connect timeout, read timeout). If only one float is passed then both connect and read timeout will be set to that value.

  • proxies (dict, str or None, optional) – Proxies to be used for requests. Are used by both ‘requests’ and ‘aiohttp’. Can be passed as a dict (‘requests’ format: https://docs.python-requests.org/en/stable/user/advanced/#proxies), str (HTTP/HTTPS protocols are going to use this proxy) or None.

  • trust_env (bool, optional) – Whether to read proxies from the ENV variables: (HTTP_PROXY or http_proxy, HTTPS_PROXY or https_proxy). NOTE: ‘proxies’ has priority over ‘trust_env’, i.e. if ‘proxies’ is NOT None, ‘trust_env’ is ignored.

  • additional_headers (Dict[str, Any] or None) – Additional headers to include in the requests, used to set OpenAI key. OpenAI key looks like this: {‘X-OpenAI-Api-Key’: ‘KEY’}.

  • startup_period (int or None) – How long the client will wait for weaviate to start before raising a RequestsConnectionError. If None the client will not wait at all.

Raises:

ValueError – If no authentication credentials provided but the Weaviate server has an OpenID configured.

close() None

Shutdown connection class gracefully.

delete(path: str, weaviate_object: dict | list | None = None, params: Dict[str, Any] | None = None) Response

Make a DELETE request to the Weaviate server instance.

Parameters:
  • path (str) – Sub-path to the Weaviate resources. Must be a valid Weaviate sub-path. e.g. ‘/meta’ or ‘/objects’, without version.

  • weaviate_object (dict, optional) – Object is used as payload for DELETE request. By default None.

  • params (dict, optional) – Additional request parameters, by default None

Returns:

The response, if request was successful.

Return type:

requests.Response

Raises:

requests.ConnectionError – If the DELETE request could not be made.

get(path: str, params: Dict[str, Any] | None = None, external_url: bool = False) Response

Make a GET request.

Parameters:
  • path (str) – Sub-path to the Weaviate resources. Must be a valid Weaviate sub-path. e.g. ‘/meta’ or ‘/objects’, without version.

  • params (dict, optional) – Additional request parameters, by default None

  • external_url (Is an external (non-weaviate) url called) –

Returns:

The response if request was successful.

Return type:

requests.Response

Raises:

requests.ConnectionError – If the GET request could not be made.

get_current_bearer_token() str
get_meta() Dict[str, str]

Returns the meta endpoint.

property grpc_stub: weaviate_pb2_grpc.WeaviateStub | None
head(path: str, params: Dict[str, Any] | None = None) Response

Make a HEAD request to the server.

Parameters:
  • path (str) – Sub-path to the resources. Must be a valid sub-path. e.g. ‘/meta’ or ‘/objects’, without version.

  • params (dict, optional) – Additional request parameters, by default None

Returns:

The response to the request.

Return type:

requests.Response

Raises:

requests.ConnectionError – If the HEAD request could not be made.

patch(path: str, weaviate_object: dict | list, params: Dict[str, Any] | None = None) Response

Make a PATCH request to the Weaviate server instance.

Parameters:
  • path (str) – Sub-path to the Weaviate resources. Must be a valid Weaviate sub-path. e.g. ‘/meta’ or ‘/objects’, without version.

  • weaviate_object (dict) – Object is used as payload for PATCH request.

  • params (dict, optional) – Additional request parameters, by default None

Returns:

The response, if request was successful.

Return type:

requests.Response

Raises:

requests.ConnectionError – If the PATCH request could not be made.

post(path: str, weaviate_object: dict | list, params: Dict[str, Any] | None = None) Response

Make a POST request to the Weaviate server instance.

Parameters:
  • path (str) – Sub-path to the Weaviate resources. Must be a valid Weaviate sub-path. e.g. ‘/meta’ or ‘/objects’, without version.

  • weaviate_object (dict) – Object is used as payload for POST request.

  • params (dict, optional) – Additional request parameters, by default None

  • external_url (Is an external (non-weaviate) url called) –

Returns:

The response, if request was successful.

Return type:

requests.Response

Raises:

requests.ConnectionError – If the POST request could not be made.

property proxies: dict
put(path: str, weaviate_object: dict | list, params: Dict[str, Any] | None = None) Response

Make a PUT request to the Weaviate server instance.

Parameters:
  • path (str) – Sub-path to the Weaviate resources. Must be a valid Weaviate sub-path. e.g. ‘/meta’ or ‘/objects’, without version.

  • weaviate_object (dict) – Object is used as payload for PUT request.

  • params (dict, optional) – Additional request parameters, by default None

Returns:

The response, if request was successful.

Return type:

requests.Response

Raises:

requests.ConnectionError – If the PUT request could not be made.

property server_version: str

Version of the weaviate instance.

property timeout_config: Tuple[int | float, int | float]

Getter/setter for timeout_config.

Parameters:

timeout_config (tuple(float, float), optional) –

For Setter only: Set the timeout configuration for all requests to the Weaviate server. It can be a float or, a tuple of two floats:

(connect timeout, read timeout).

If only one float is passed then both connect and read timeout will be set to that value.

Returns:

For Getter only: Requests Timeout configuration.

Return type:

Tuple[float, float]

wait_for_weaviate(startup_period: int) None

Waits until weaviate is ready or the timelimit given in ‘startup_period’ has passed.

Parameters:

startup_period (int) – Describes how long the client will wait for weaviate to start in seconds.

Raises:

WeaviateStartUpError – If weaviate takes longer than the timelimit to respond.