How to Create a Schema Using Python Client V4 via a Custom API Endpoint?

Hi everyone,

I’m currently using the Python Client v4 for Weaviate. Here’s the code snippet I use to create a schema directly in Python:

collection = self.client.collections.create(
    name=collection_name,
    vectorizer_config=wvc.config.Configure.Vectorizer.text2vec_openai()
)

In the above code, I’m only providing the collection_name and vectorizer_config, and the rest of the values are set to default.

Now, I am converting this functionality into a custom API class. I need to pass the schema details through the API body and create the schema programmatically via an HTTP POST request.

For example:

  • Endpoint: POST http://localhost:8311/matching-engine/v1/collection/add_schema
  • Request Body: Contains schema details.

I want to achieve this without using the default Weaviate endpoint like:

curl http://localhost:8080/v1/schema \
  --request POST \
  --header 'Content-Type: text/plain;charset=UTF-8'

Could someone guide me on how to structure the API body and write the server-side logic in Python to handle this? Any code examples or documentation references would be greatly appreciated.

Thanks in advance!

@DudaNogueira Need your guidance here

Hi!

Not sure I understood it here.

In order to create a collection, that’s the only endpoint available:

the client, by the way, is using that very same endpoint.

So you can use both the direct call to that api or the client, that will under the hood also call that endpoint.

I have defined my client like below

        self.client = weaviate.connect_to_custom(
            http_host=host,
            http_port=port,
            http_secure=False,
            grpc_secure=False,
            grpc_host=grpc_host,
            grpc_port=grpc_port,
            headers={
                "X-OpenAI-Api-Key": os.environ.get("OPENAI_APIKEY", "")
            }
        )

so If I call default endpoint will it follow the authentication.

I want to using python

Yes, you can both use the python client or call the endpoint directly.

If you have set the auth in Weaviate server, you can use it as a bearer token for the rest call