Excellent question! You've hit upon one of the most significant and positive changes in the Weaviate Python client v4.
You are absolutely correct. In v4, the Client object was replaced by WeaviateClient, and the client.schema attribute was removed. The new, more intuitive way to manage schemas is through the client.collections attribute.
The core conceptual shift is that in v4, a "schema" for a class is now managed through a "Collection" object. A collection encapsulates the schema (configuration), data, and querying for a specific class of objects.
The New Way: Using client.collections
Here are the direct replacements for what you used to do with client.schema.get().
1. To Get the Configuration of a Specific Collection (Class)
This is the most common use case and the direct equivalent of client.schema.get("MyClassName").
The new method is client.collections.get("CollectionName").
This method returns a Collection object, and you can access its configuration through the .config attribute.
import weaviate
import weaviate.classes as wvc
# Connect to your Weaviate instance
# Make sure to replace with your actual URL and API key if needed
client = weaviate.connect_to_local(
headers={
"X-OpenAI-Api-Key": "YOUR-OPENAI-API-KEY" # Or other vectorization provider
}
)
try:
# Let's assume a collection named "Article" exists
collection_name = "Article"
# The new way to get a specific collection's schema/config
article_collection = client.collections.get(collection_name)
# The returned object is a Collection instance.
# Its configuration is available under the .config attribute.
print(f"--- Configuration for '{collection_name}' ---")
# You can print the raw config dictionary
# This is the most direct view of the schema
raw_config = article_collection.config.get_raw()
print(raw_config)
# You can also access individual properties
print(f"\nVectorizer: {article_collection.config.get().vectorizer}")
print(f"Vector Index Type: {article_collection.config.get().vector_index_type}")
except weaviate.exceptions.WeaviateQueryError as e:
print(f"Collection '{collection_name}' not found or an error occurred: {e}")
finally:
client.close()
2. To Get a List of All Collections (the Entire Schema)
This replaces the old behavior of client.schema.get() without any arguments.
The new method is client.collections.list_all().
This returns a dictionary where keys are collection names and values are Collection objects.
import weaviate
import weaviate.classes as wvc
client = weaviate.connect_to_local()
try:
# Get all collections
all_collections = client.collections.list_all()
print("--- All Collections in Weaviate Instance ---")
if not all_collections:
print("No collections found.")
else:
# all_collections is a dict[str, Collection]
for name, collection in all_collections.items():
print(f"\nCollection Name: {name}")
# Get the configuration for each collection
config = collection.config.get()
print(f" - Vectorizer: {config.vectorizer}")
print(f" - Properties: {[prop.name for prop in config.properties]}")
finally:
client.close()
Summary of the v3 to v4 Change
The change reflects a move to a more object-oriented and resource-focused API design. Instead of having separate managers for schema, data, and query, these functionalities are now grouped under the Collection object that they operate on.
| Task | v3 Python Client (weaviate-client) | v4 Python Client (weaviate-client) |
|---|
| Get a specific class schema | client.schema.get("MyClass") | collection = client.collections.get("MyClass") collection.config.get() |
| Get all class schemas | client.schema.get() | client.collections.list_all() |
| Create a class schema | client.schema.create_class(...) | client.collections.create(...) |
| Delete a class | client.schema.delete_class("MyClass") | client.collections.delete("MyClass") |
| Check if a class exists | client.schema.exists("MyClass") | client.collections.exists("MyClass") |
The key takeaway: In v4, stop thinking about a separate "schema" and start thinking about "collections". A collection is the schema, the data, and the query interface all in one.