weaviate¶
Weaviate Python Client Library used to interact with a Weaviate instance.
The interaction with Weaviate instance should be through a Client object. A Client instance has instance attributes to all the object needed to create objects/schema, do classification, upload batches, query data, … Creating separate Schema, DataObject, Batch, Classification, Query, Connect, Reference is STRONGLY DISCOURAGED. The Client class creates the needed instances and connects all of them to the same Weaviate instance for you.
Examples
A Weaviate instance running on localhost, on port 8080. With Authentication disables.
>>> import weaviate
>>> client = weaviate.Client('http://localhost:8080')
>>> print_type = lambda obj: print(type(obj))
>>> print_type(client.batch)
<class 'weaviate.batch.crud_batch.Batch'>
>>> print_type(client.schema)
<class 'weaviate.schema.crud_schema.Schema'>
>>> print_type(client.classification)
<class 'weaviate.classification.classify.Classification'>
>>> print_type(client.data_object)
<class 'weaviate.data.crud_data.DataObject'>
>>> print_type(client.query)
<class 'weaviate.gql.query.Query'>
- weaviate.__version__¶
Current weaviate-python library version installed.
- Type
str
- class weaviate.AuthClientCredentials(client_secret: str)¶
Bases:
weaviate.auth.AuthCredentials
Using a client secret for authentication. In case of grand type client credentials.
Using a client secret for authentication. In case of grand type client credentials.
- Parameters
client_secret (str) – The access token.
- get_credentials() dict ¶
Get decoded credentials.
- Returns
Decoded credentials.
- Return type
dict
- class weaviate.AuthClientPassword(username: str, password: str)¶
Bases:
weaviate.auth.AuthCredentials
Using username and password for authentication. In case of grand type password.
Using username and password for authentication. In case of grand type password.
- Parameters
username (str) – The username to login with.
password (str) – Password fot the given User.
- get_credentials() dict ¶
Get decoded credentials.
- Returns
Decoded credentials.
- Return type
dict
- exception weaviate.AuthenticationFailedException¶
Bases:
Exception
Authentication Failed Exception.
- class weaviate.Client(url: str, auth_client_secret: Optional[weaviate.auth.AuthCredentials] = None, timeout_config: Union[Tuple[numbers.Real, numbers.Real], numbers.Real] = (2, 20))¶
Bases:
object
A python native weaviate Client class that encapsulates Weaviate functionalities in one object. A Client instance creates all the needed objects to interact with Weaviate, and connects all of them to the same Weaviate instance. See below the Attributes of the Client instance. For the per attribute functionality see that attribute’s documentation.
- classification¶
A Classification object instance connected to the same Weaviate instance as the Client.
- schema¶
A Schema object instance connected to the same Weaviate instance as the Client.
- contextionary¶
A Contextionary object instance connected to the same Weaviate instance as the Client.
- batch¶
A Batch object instance connected to the same Weaviate instance as the Client.
- Type
- data_object¶
A DataObject object instance connected to the same Weaviate instance as the Client.
- Type
weaviate.date.DataObject
- query¶
A Query object instance connected to the same Weaviate instance as the Client.
- Type
Initialize a Client class instance.
- Parameters
url (str) – The URL to the weaviate instance.
auth_client_secret (weaviate.AuthCredentials, optional) – Authentication client secret, by default None.
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, by default (2, 20).
Examples
Without Auth.
>>> client = Client( ... url = 'http://localhost:8080' ... ) >>> client = Client( ... url = 'http://localhost:8080', ... timeout_config = (5, 15) ... )
With Auth.
>>> my_credentials = weaviate.auth.AuthClientPassword(USER_NAME, MY_PASSWORD) >>> client = Client( ... url = 'http://localhost:8080', ... auth_client_secret = my_credentials ... )
- Raises
TypeError – If arguments are of a wrong data type.
- get_meta() dict ¶
Get the meta endpoint description of weaviate.
- Returns
The dict describing the weaviate configuration.
- Return type
dict
- Raises
weaviate.UnexpectedStatusCodeException – If weaviate reports a none OK status.
- get_open_id_configuration() Optional[dict] ¶
Get the openid-configuration.
- Returns
The configuration or None if not configured.
- Return type
dict
- Raises
weaviate.UnexpectedStatusCodeException – If weaviate reports a none OK status.
- is_live() bool ¶
Ping Weaviate’s live state.
- Returns
True if weaviate is live and should not be killed, False otherwise.
- Return type
bool
- is_ready() bool ¶
Ping Weaviate’s ready state
- Returns
True if Weaviate is ready to accept requests, False otherwise.
- Return type
bool
- property timeout_config: Tuple[numbers.Real, numbers.Real]¶
Getter/setter for timeout_config.
- Parameters
timeout_config (tuple(Real, Real) or Real, optional) –
For Getter 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]
- exception weaviate.ObjectAlreadyExistsException¶
Bases:
Exception
Object Already Exists Exception.
- exception weaviate.SchemaValidationException¶
Bases:
Exception
Schema Validation Exception.
- exception weaviate.UnexpectedStatusCodeException(message: str, response: requests.models.Response)¶
Bases:
Exception
Is raised in case the status code returned from Weaviate is not handled in the client implementation and suggests an error.
Is raised in case the status code returned from Weaviate is not handled in the client implementation and suggests an error.
Custom code can act on the attributes: - status_code - json
- Parameters
message (str) – An error message specific to the context, in which the error occurred.
response (requests.Response) – The request response of which the status code was unexpected.