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: Optional[weaviate.auth.AuthCredentials], timeout_config: Union[Tuple[numbers.Real, numbers.Real], numbers.Real], proxies: Optional[Union[dict, str]], trust_env: bool, additional_headers: Optional[dict])¶
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) – User login credentials to a weaviate instance.
timeout_config (tuple(Real, Real) or Real, optional) – Set the timeout configuration for all requests to the Weaviate server. It can be a real number or, a tuple of two real numbers: (connect timeout, read timeout). If only one real number 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 or None) – Additional headers to include in the requests, used to set OpenAI key. OpenAI key looks like this: {‘X-OpenAI-Api-Key’: ‘KEY’}.
- Raises
ValueError – If no authentication credentials provided but the Weaviate server has an OpenID configured.
- delete(path: str, weaviate_object: Optional[dict] = None) requests.models.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.
- 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: Optional[dict] = None) requests.models.Response ¶
Make a GET 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.
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 GET request could not be made.
- head(path: str) requests.models.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.
- 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) requests.models.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.
- 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) requests.models.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.
- Returns
The response, if request was successful.
- Return type
requests.Response
- Raises
requests.ConnectionError – If the POST request could not be made.
- put(path: str, weaviate_object: dict) requests.models.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.
- 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: Tuple[numbers.Real, numbers.Real]¶
Getter/setter for Weaviate server_version.
- Parameters
server_version (str) – For Setter only: The Weaviate server version gotten from the Client.get_meta().
- Returns
For Getter only: Weaviate server version.
- Return type
str
- property timeout_config: Tuple[numbers.Real, numbers.Real]¶
Getter/setter for timeout_config.
- Parameters
timeout_config (tuple(Real, Real) or Real, optional) –
For Setter only: Set the timeout configuration for all requests to the Weaviate server. It can be a real number or, a tuple of two real numbers:
(connect timeout, read timeout).
If only one real number is passed then both connect and read timeout will be set to that value.
- Returns
For Getter only: Requests Timeout configuration.
- Return type
Tuple[Real, Real]