
    ?h-                        d Z ddlmZmZmZmZmZ ddlmZ	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZ ddlmZ ddlmZ ddlmZmZ ddl m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z)m*Z* eee'e'f   e'f   Z+ G d d      Z,y)z
Client class definition.
    )OptionalTupleUnionDictAny)ConnectionError   )AuthCredentials)Backup)Batch)Classification)Cluster)Config)
ConnectionTIMEOUT_TYPE_RETURN)Contextionary)
DataObject)
EmbeddedDBEmbeddedOptions)UnexpectedStatusCodeException)Query)Schema)NUMBERS)_get_valid_timeout_config_type_request_responsec                   J   e Zd ZdZ	 	 	 	 	 	 	 	 	 ddee   dee   dedee	edf   de
dee	   d	ee   d
ee   dee   ddfdZde
fdZde
fdZde	fdZdeeeef      fdZedefd       Zej0                  deddfd       Zedee   d
ee   deeee   f   fd       ZddZy)Clienta  
    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.

    Attributes
    ----------
    backup : weaviate.backup.Backup
        A Backup object instance connected to the same Weaviate instance as the Client.
    batch : weaviate.batch.Batch
        A Batch object instance connected to the same Weaviate instance as the Client.
    classification : weaviate.classification.Classification
        A Classification object instance connected to the same Weaviate instance as the Client.
    cluster : weaviate.cluster.Cluster
        A Cluster object instance connected to the same Weaviate instance as the Client.
    contextionary : weaviate.contextionary.Contextionary
        A Contextionary object instance connected to the same Weaviate instance as the Client.
    data_object : weaviate.data.DataObject
        A DataObject object instance connected to the same Weaviate instance as the Client.
    schema : weaviate.schema.Schema
        A Schema object instance connected to the same Weaviate instance as the Client.
    query : weaviate.gql.Query
        A Query object instance connected to the same Weaviate instance as the Client.
    Nurlauth_client_secrettimeout_configproxies	trust_envadditional_headersstartup_periodembedded_optionsadditional_configreturnc
                 X   |	
t               n|	}
| j                  ||      \  }}t        ||t        |      ||||||
j                  |
j
                  
      | _        t        | j                        | _        t        | j                        | _
        t        | j                        | _        t        | j                        | _        t        | j                        | _        t#        | j                        | _        t'        | j                        | _        t+        | j                        | _        y)ah  
        Initialize a Client class instance.

        Parameters
        ----------
        url : str
            The URL to the weaviate instance.
        auth_client_secret : weaviate.AuthCredentials or None, optional
        # fmt: off
            Authenticate to weaviate by using one of the given authentication modes:
            - weaviate.auth.AuthBearerToken to use existing access and (optionally, but recommended) refresh tokens
            - weaviate.auth.AuthClientPassword to use username and password for oidc Resource Owner Password flow
            - weaviate.auth.AuthClientCredentials to use a client secret for oidc client credential flow

        # fmt: on
        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).
        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.
            Default None.
        trust_env : bool, optional
            Whether to read proxies from the ENV variables: (HTTP_PROXY or http_proxy, HTTPS_PROXY
            or https_proxy). Default False.
            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.
            Can be used to set OpenAI/HuggingFace keys. OpenAI/HuggingFace key looks like this:
                {"X-OpenAI-Api-Key": "<THE-KEY>"}, {"X-HuggingFace-Api-Key": "<THE-KEY>"}
            by default None
        startup_period : int or None
            How long the client will wait for Weaviate to start before raising a RequestsConnectionError.
            If None, the client won't wait at all. Default timeout is 5s.
        embedded_options : weaviate.embedded.EmbeddedOptions or None, optional
            Create an embedded Weaviate cluster inside the client
            - You can pass weaviate.embedded.EmbeddedOptions() with default values
            - Take a look at the attributes of weaviate.embedded.EmbeddedOptions to see what is configurable
        additional_config: weaviate.Config, optional
            Additional and advanced configuration options for weaviate.
        Examples
        --------
        Without Auth.

        >>> client = Client(
        ...     url = 'http://localhost:8080'
        ... )
        >>> client = Client(
        ...     url = 'http://localhost:8080',
        ...     timeout_config = (5, 15)
        ... )

        With Auth.

        >>> my_credentials = weaviate.AuthClientPassword(USER_NAME, MY_PASSWORD)
        >>> client = Client(
        ...     url = 'http://localhost:8080',
        ...     auth_client_secret = my_credentials
        ... )

        Creating a client with an embedded database:

        >>> from weaviate import EmbeddedOptions
        >>> client = Client(embedded_options=EmbeddedOptions())

        Creating a client with additional configurations:

        >>> from weaviate import Config
        >>> client = Client(additional_config=Config())


        Raises
        ------
        TypeError
            If arguments are of a wrong data type.
        N)
r   r   r    r!   r"   r#   r$   embedded_db	grcp_portconnection_config)r   "_Client__parse_url_and_embedded_dbr   r   grpc_port_experimentalr+   _connectionr   classificationr   schemar   contextionaryr   batchr   data_objectr   queryr   backupr   cluster)selfr   r   r    r!   r"   r#   r$   r%   r&   configr)   s               M/home/chris/cleankitchens-env/lib/python3.12/site-packages/weaviate/client.py__init__zClient.__init__6   s    z /6<M;;CAQR[%14^D1)#33$66
 -T-=-=>T--.*4+;+;<4++,
%d&6&674++,
T--.t//0    c                 |    	 | j                   j                  d      }|j                  dk(  ryy# t        $ r Y yw xY w)z
        Ping Weaviate's ready state

        Returns
        -------
        bool
            True if Weaviate is ready to accept requests,
            False otherwise.
        z/.well-known/readypath   TF)r.   getstatus_codeRequestsConnectionErrorr7   responses     r9   is_readyzClient.is_ready   sG    	''++1E+FH##s*& 		s   +/ 	;;c                 \    | j                   j                  d      }|j                  dk(  ryy)z
        Ping Weaviate's live state.

        Returns
        --------
        bool
            True if weaviate is live and should not be killed,
            False otherwise.
        z/.well-known/liver=   r?   TF)r.   r@   rA   rC   s     r9   is_livezClient.is_live   s2     ##''-@'A3&r;   c                 6    | j                   j                         S )a*  
        Get the meta endpoint description of weaviate.

        Returns
        -------
        dict
            The dict describing the weaviate configuration.

        Raises
        ------
        weaviate.UnexpectedStatusCodeException
            If weaviate reports a none OK status.
        )r.   get_metar7   s    r9   rI   zClient.get_meta   s     ((**r;   c                     | j                   j                  d      }|j                  dk(  rt        |j	                               S |j                  dk(  ryt        d|      )a  
        Get the openid-configuration.

        Returns
        -------
        dict
            The configuration or None if not configured.

        Raises
        ------
        weaviate.UnexpectedStatusCodeException
            If weaviate reports a none OK status.
        z!/.well-known/openid-configurationr=   r?   i  NzMeta endpoint)r.   r@   rA   r   jsonr   rC   s     r9   get_open_id_configurationz Client.get_open_id_configuration   s[     ##''-P'Q3&)(--/::3&+OXFFr;   c                 .    | j                   j                  S )al  
        Getter/setter for `timeout_config`.

        Parameters
        ----------
        timeout_config : tuple(float, float) or float, 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
        -------
        Tuple[float, float]
            For Getter only: Requests Timeout configuration.
        )r.   r    rJ   s    r9   r    zClient.timeout_config   s    ( ...r;   c                 8    t        |      | j                  _        y)zW
        Setter for `timeout_config`. (docstring should be only in the Getter)
        N)r   r.   r    )r7   r    s     r9   r    zClient.timeout_config  s     +DN*S'r;   c                 *   || t        d      || t        d|        |7t        |      }|j                          d|j                  j                   |fS t        | t              st        dt        |              | j                  d      d fS )Nz/Either url or embedded options must be present.zFURL is not expected to be set when using embedded_options but URL was )optionszhttp://localhost:z$URL is expected to be string but is /)		TypeErrorr   startrQ   port
isinstancestrtypestrip)r   r%   r)   s      r9   __parse_url_and_embedded_dbz"Client.__parse_url_and_embedded_db  s     #MNN)coXY\X]^  '$-=>K&{':':'?'?&@A;NN#s#B49+NOOyy~t##r;   c                 R    t        | d      r| j                  j                          y y )Nr.   )hasattrr.   closerJ   s    r9   __del__zClient.__del__'  s#    4'""$ (r;   )	NN)
   <   NFN   NN)r'   N)__name__
__module____qualname____doc__r   rW   r
   TIMEOUT_TYPEr   dictboolintr   r   r:   rE   rG   rI   r   r   rM   propertyr   r    setterstaticmethodr   r   r,   r^    r;   r9   r   r      s   8 "8<'/*.-1()6:.2s1c]s1 %_5s1 %	s1
 tS$'s1 s1 %TNs1 !s1 #?3s1 $F+s1 
s1j$ &  +$ +"G8DcN+C G, / 3 / /* T\ Td T T $c]$.6.G$	sHZ((	)$ $&%r;   r   N)-re   typingr   r   r   r   r   requests.exceptionsr   rB   authr
   r5   r   r2   r   r/   r   r6   r   r8   r   connect.connectionr   r   r1   r   datar   embeddedr   r   
exceptionsr   gqlr   r0   r   typesr   utilr   r   rf   r   rm   r;   r9   <module>rx      sg    5 4 J !   *   ? (  1 5    CU7G+,g56O% O%r;   