### Install Weaviate Python Client Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/index.md Install the Weaviate Python client using pip. This is the standard installation for basic usage. ```bash pip install -U weaviate-client ``` -------------------------------- ### Install Weaviate Python Client with Agent Support Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/index.md Install the Weaviate Python client with optional agent support using the `[agents]` extra. This enables integration with Weaviate Agents for LLM-related tasks. ```bash pip install -U "weaviate-client[agents]" ``` -------------------------------- ### gRPC Configuration Example Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.classes.md Example of how to configure gRPC channel options and credentials for the Weaviate client. ```python from grpc import ssl_channel_credentials import weaviate.classes as wvc conf = wvc.init.GrpcConfig( channel_options=[ ("grpc.keepalive_time_ms", 10000), ("grpc.keepalive_timeout_ms", 5000), ], credentials=ssl_channel_credentials(openssl_cafile=None, ssl_context=None, key_file=None, cert_file=None) ) ``` -------------------------------- ### Pre-build hook for cloning and installing the agents client Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/PUBLISHING.md This YAML snippet shows how the weaviate-agents-python-client is cloned and installed as a pre-build step in Read the Docs. ```yaml build: jobs: pre_build: - git clone -b main --depth=1 https://github.com/weaviate/weaviate-agents-python-client.git docs/weaviate-agents-python-client - python -m pip install -e ./docs/weaviate-agents-python-client ``` -------------------------------- ### Initialize BM25 Query and Generate Classes Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.queries.bm25.md Example demonstrating the constructor signature for the internal BM25 query and generation classes. These classes require a connection object, collection name, and optional configuration for consistency, multi-tenancy, and data mapping. ```python from weaviate.collections.queries.bm25 import _BM25Query, _BM25Generate # Example instantiation pattern for internal BM25 classes query_instance = _BM25Query( connection=connection, name="MyCollection", consistency_level=None, tenant=None, properties=None, references=None, validate_arguments=True ) generate_instance = _BM25Generate( connection=connection, name="MyCollection", consistency_level=None, tenant=None, properties=None, references=None, validate_arguments=True ) ``` -------------------------------- ### Manage Embedded Database Lifecycle Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.md Demonstrates how to initialize and control the lifecycle of an embedded Weaviate database instance using the EmbeddedV3 or EmbeddedV4 classes. Methods include checking connectivity and starting the service. ```python from weaviate.embedded import EmbeddedV4, EmbeddedOptions options = EmbeddedOptions(port=8079) embedded_db = EmbeddedV4(options=options) if not embedded_db.is_listening(): embedded_db.start() ``` -------------------------------- ### Create Weaviate Collection from Dictionary (Async) Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.collections.md Create a new collection in Weaviate using a configuration dictionary and immediately get a collection object. This is useful for v3 to v4 migrations and experimental features. Requires a successful connection to Weaviate. ```python from weaviate.collections.collection import CollectionAsync # Assuming 'connection_async' is an initialized ConnectionAsync object collections_async = _CollectionsAsync(connection_async) collection_config_dict = { "class": "MyNewCollection", "description": "A new collection created from a dictionary", "properties": [ { "name": "title", "dataType": ["text"] } ] } # The return type is CollectionAsync, but without generic types specified here new_collection: CollectionAsync = await collections_async.create_from_dict(config=collection_config_dict) ``` -------------------------------- ### Initialize and Connect to Local Weaviate Async Client Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.md Demonstrates how to initialize a local Weaviate async client. It shows both the manual approach using connect/close methods and the recommended approach using an async context manager for automatic resource cleanup. ```python import weaviate # Without Context Manager client = weaviate.use_async_with_local( host="localhost", port=8080, grpc_port=50051, ) await client.connect() # ... perform operations ... await client.close() # With Context Manager async with weaviate.use_async_with_local( host="localhost", port=8080, grpc_port=50051, ) as client: is_ready = await client.is_ready() print(is_ready) ``` -------------------------------- ### Initialize and Connect to Embedded Weaviate Async Client Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.md Demonstrates how to initialize an embedded async client, connect to it, and verify readiness. It also shows the recommended approach using an async context manager for automatic resource cleanup. ```python import weaviate # Manual connection management client = weaviate.use_async_with_embedded( port=8080, grpc_port=50051 ) await client.connect() ready = await client.is_ready() # Using context manager for automatic cleanup async with weaviate.use_async_with_embedded( port=8080, grpc_port=50051 ) as client: ready = await client.is_ready() ``` -------------------------------- ### CrossReferenceAnnotation Example Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.classes.md Example demonstrating how to use CrossReferenceAnnotation to include vectors and metadata when querying cross-referenced objects. ```python >>> import typing >>> import weaviate.classes as wvc >>> >>> class One(typing.TypedDict): ... prop: str >>> >>> class Two(typing.TypedDict): ... one: typing.Annotated[ ... wvc.CrossReference[One], ... wvc.CrossReferenceAnnotation(include_vector=True) ... ] ``` -------------------------------- ### Async Batch Wrapper Get Shards Readiness Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.batch.md Internal method to get shard readiness status asynchronously. ```APIDOC ## async _BatchWrapperAsync__get_shards_readiness ### Description Internal method to get shard readiness status asynchronously. ### Method ASYNC ### Parameters #### Path Parameters - **shard** (Shard) - Required - The shard to check the status of. ### Return type List[bool] ``` -------------------------------- ### Initialize Collection Configuration Classes Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.config.md Demonstrates the instantiation of synchronous and asynchronous configuration objects for a Weaviate collection. These classes require a connection object and the collection name, with an optional tenant identifier. ```python from weaviate.collections.config import _ConfigCollection, _ConfigCollectionAsync # Synchronous configuration access sync_config = _ConfigCollection(connection=conn, name="MyCollection", tenant="tenant_a") # Asynchronous configuration access async_config = _ConfigCollectionAsync(connection=conn, name="MyCollection", tenant="tenant_a") ``` -------------------------------- ### CrossReference Type Hint Example Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.classes.md Example of how to use CrossReference for type hinting within a generic data model. ```python >>> import typing >>> import weaviate.classes as wvc >>> >>> class One(typing.TypedDict): ... prop: str >>> >>> class Two(typing.TypedDict): ... one: wvc.CrossReference[One] ``` -------------------------------- ### Initialize Collection Backup Classes Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.backups.md Demonstrates how to instantiate the synchronous and asynchronous backup handlers. These classes require a connection object and the name of the backup to operate. ```python from weaviate.collections.backups import _CollectionBackup, _CollectionBackupAsync # Synchronous initialization sync_backup = _CollectionBackup(connection=my_connection, name="backup_name") # Asynchronous initialization async_backup = _CollectionBackupAsync(connection=my_connection, name="backup_name") ``` -------------------------------- ### Connect to Embedded Weaviate Instance Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.md Demonstrates how to initialize an embedded Weaviate client using standard connection parameters. It shows both manual connection management and the recommended context manager pattern to ensure resources are properly released. ```python import weaviate # Manual connection management client = weaviate.connect_to_embedded( port=8080, grpc_port=50051, ) print(client.is_ready()) client.close() # Using a context manager for automatic resource cleanup with weaviate.connect_to_embedded( port=8080, grpc_port=50051, ) as client: print(client.is_ready()) ``` -------------------------------- ### Build HTML Documentation Locally Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/README.rst Commands to build the HTML documentation locally from the 'docs' directory and open the generated index file. ```bash make html ``` ```bash open _build/html/index.html ``` -------------------------------- ### GET number_errors Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.batch.md Retrieves the count of errors encountered in the current batch. ```APIDOC ## GET number_errors ### Description Get the number of errors in the current batch. ### Response - **Returns** (int) - The number of errors in the current batch. ``` -------------------------------- ### GET /batch/errors Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.batch.md Retrieves the count of errors encountered in the current batch. ```APIDOC ## GET /batch/errors ### Description Get the number of errors in the current batch. ### Response #### Success Response (200) - **count** (int) - The number of errors in the current batch. ``` -------------------------------- ### Get Batch Results Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.batch.md Retrieves the overall results of the batch operation. ```APIDOC ## property results ### Description Get the results of the batch operation. ### Returns The results of the batch operation. ### Return type BatchResult ``` -------------------------------- ### Connect to Weaviate Cloud Instance Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.md Demonstrates how to initialize a connection to a Weaviate Cloud cluster using API key authentication. It shows both the manual approach requiring a close() call and the recommended context manager pattern. ```python import weaviate # Manual connection management client = weaviate.connect_to_weaviate_cloud( cluster_url="rAnD0mD1g1t5.something.weaviate.cloud", auth_credentials=weaviate.classes.init.Auth.api_key("my-api-key"), ) client.is_ready() client.close() # Using context manager for automatic cleanup with weaviate.connect_to_weaviate_cloud( cluster_url="rAnD0mD1g1t5.something.weaviate.cloud", auth_credentials=weaviate.classes.init.Auth.api_key("my-api-key"), ) as client: client.is_ready() ``` -------------------------------- ### GET /v1/nodes Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/modules.md Checks the status and readiness of the Weaviate cluster nodes. ```APIDOC ## GET /v1/nodes ### Description Returns the status of the nodes in the cluster, indicating if they are ready to accept requests. ### Method GET ### Endpoint /v1/nodes ### Parameters None ### Request Example GET /v1/nodes ### Response #### Success Response (200) - **nodes** (array) - List of node status objects. #### Response Example { "nodes": [ { "name": "node-1", "status": "HEALTHY" } ] } ``` -------------------------------- ### Connect to a local Weaviate instance Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.md Demonstrates how to connect to a local Weaviate instance using the Python client. It shows both the manual approach requiring a call to .close() and the recommended context manager approach for automatic resource management. ```python import weaviate # Approach 1: Manual connection management client = weaviate.connect_to_local( host="localhost", port=8080, grpc_port=50051 ) client.is_ready() client.close() # Approach 2: Using a context manager (Recommended) with weaviate.connect_to_local( host="localhost", port=8080, grpc_port=50051 ) as client: client.is_ready() ``` -------------------------------- ### Get Number of Errors in Batch Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.batch.md Retrieves the number of errors encountered in the current batch. ```APIDOC ## GET /batch/errors/count ### Description Retrieves the number of errors encountered in the current batch. ### Method GET ### Endpoint /batch/errors/count ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **count** (int) - The number of errors in the current batch. #### Response Example ```json { "count": 0 } ``` ``` -------------------------------- ### Get Failed References Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.batch.md Retrieves a list of all references that failed during the batch import process. ```APIDOC ## property failed_references ### Description Get all failed references from the batch manager. ### Returns A list of all the failed references from the batch. ### Return type List[ErrorReference] ``` -------------------------------- ### Initialize Near Image Query Classes Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.queries.near_image.md Demonstrates the instantiation of the internal _NearImageQuery and _NearImageGenerate classes. These classes require a connection object, collection name, and optional configuration for consistency, multi-tenancy, and property mapping. ```python from weaviate.collections.queries.near_image import _NearImageQuery, _NearImageGenerate # Example instantiation of the query class near_image_query = _NearImageQuery( connection=connection, name="MyCollection", consistency_level=None, tenant=None, properties=None, references=None, validate_arguments=True ) # Example instantiation of the generative query class near_image_gen = _NearImageGenerate( connection=connection, name="MyCollection", consistency_level=None, tenant=None, properties=None, references=None, validate_arguments=True ) ``` -------------------------------- ### Get Failed Objects Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.batch.md Retrieves a list of all objects that failed during the batch import process. ```APIDOC ## property failed_objects ### Description Get all failed objects from the batch manager. ### Returns A list of all the failed objects from the batch. ### Return type List[ErrorObject] ``` -------------------------------- ### Create Async Weaviate Client with Custom Parameters (Python) Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.md This snippet demonstrates how to initialize an asynchronous Weaviate client with specific HTTP and gRPC connection details. It shows both manual connection management (connect/close) and the preferred method using an async context manager for automatic connection handling. ```python import weaviate # Without Context Manager client = weaviate.use_async_with_custom( http_host="localhost", http_port=8080, http_secure=False, grpc_host="localhost", grpc_port=50051, grpc_secure=False, ) # Manual connection and closing # await client.connect() # await client.is_ready() # await client.close() # With Async Context Manager async with weaviate.use_async_with_custom( http_host="localhost", http_port=8080, http_secure=False, grpc_host="localhost", grpc_port=50051, grpc_secure=False, ) as client: await client.is_ready() # Connection is automatically closed here ``` -------------------------------- ### Get Shard Readiness Status Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.collections.batch.md Asynchronously checks the readiness status of a given shard. ```APIDOC ## async _get_shards_readiness ### Description Checks the readiness status of a given shard. ### Method ASYNC ### Parameters #### Path Parameters - **shard** (Shard) - Required - The shard to check the status of. ### Return type List[bool] ``` -------------------------------- ### weaviate.use_async_with_custom Source: https://github.com/weaviate/weaviate-python-client/blob/main/docs/weaviate.md Initializes an asynchronous Weaviate client with specific host, port, and security configurations. ```APIDOC ## METHOD weaviate.use_async_with_custom ### Description Creates an async client object ready to connect to a Weaviate instance with custom connection parameters. This method is useful for custom infrastructure setups where standard connection helpers are insufficient. ### Parameters - **http_host** (str) - Required - The host for REST and GraphQL API calls. - **http_port** (int) - Required - The port for REST and GraphQL API calls. - **http_secure** (bool) - Required - Whether to use https. - **grpc_host** (str) - Required - The host for the gRPC API. - **grpc_port** (int) - Required - The port for the gRPC API. - **grpc_secure** (bool) - Required - Whether to use a secure gRPC channel. - **headers** (Dict[str, str]) - Optional - Additional request headers. - **additional_config** (AdditionalConfig) - Optional - Advanced configuration options. - **auth_credentials** (Auth) - Optional - Authentication credentials (API Key, Bearer Token, etc.). - **skip_init_checks** (bool) - Optional - Whether to skip initialization checks. ### Request Example ```python import weaviate client = weaviate.use_async_with_custom( http_host="localhost", http_port=8080, http_secure=False, grpc_host="localhost", grpc_port=50051, grpc_secure=False ) await client.connect() ``` ### Response - **Returns** (WeaviateAsyncClient) - An instance of the WeaviateAsyncClient ready for connection. ```