Weaviate Python Client

4.20.0 · active · verified Sat Feb 28

Official Python client for the Weaviate vector database. v4 is a complete rewrite from v3 — uses gRPC for data operations (significantly faster), strong typing, collection-centric API, and context manager connection lifecycle. v3 API (weaviate.Client class) removed from the v4 package as of late 2024. Compatible with Weaviate server >= 1.23.7. Supports local, cloud (Weaviate Cloud), and custom deployments.

Warnings

Install

Imports

Quickstart

v4 uses context manager (with ... as client) to manage connection lifecycle. collections.use() is the preferred method (collections.get() deprecated in 4.18).

import weaviate
from weaviate.classes.init import Auth

# Local Weaviate instance
with weaviate.connect_to_local() as client:
    # Create or get collection
    if not client.collections.exists('Documents'):
        client.collections.create('Documents')

    collection = client.collections.use('Documents')

    # Insert object
    uuid = collection.data.insert({'text': 'Hello world', 'source': 'test'})

    # Query
    results = collection.query.near_text(query='hello', limit=5)
    for obj in results.objects:
        print(obj.properties)

view raw JSON →