Skip to main content

Local instances

Follow these steps to connect to a locally hosted Weaviate instance.

Local connection URL

Docker instances default to http://localhost:8080. The gRPC port, 50051, is also on localhost.

If your instance runs on Kubernetes, see the host and port values in your Helm chart's values.yaml file.

No authentication enabled

To connect to a local instance without authentication, follow these examples.

import weaviate

client = weaviate.connect_to_local()

print(client.is_ready())

Change the URL or port

To change the default URL or port number, follow these examples.

import weaviate

client = weaviate.connect_to_local(
host="127.0.0.1", # Use a string to specify the host
port=8080,
grpc_port=50051,
)

print(client.is_ready())

Authentication enabled

To authenticate with a Weaviate API key, follow these examples.

import weaviate
from weaviate.classes.init import Auth

# Best practice: store your credentials in environment variables
weaviate_api_key = os.environ["WEAVIATE_API_KEY"]

client = weaviate.connect_to_local(
auth_credentials=Auth.api_key(weaviate_api_key)
)

print(client.is_ready())

assert client.is_ready()

OIDC authentication

For details on authentication with OpenID Connect (OIDC), see OIDC configuration.

For additional client examples, see OIDC authentication.

Third party API keys

Integrations that use external APIs often need API keys. To add third party API keys, follow these examples:

import os
import weaviate

# Best practice: store your credentials in environment variables
cohere_api_key = os.environ["COHERE_API_KEY"]

client = weaviate.connect_to_local(
headers={
"X-Cohere-Api-Key": cohere_api_key
}
)

print(client.is_ready())

Environment variables

danger

Do not hard-code API keys or other credentials in your client code. Use environment variables or a similar secure coding technique instead.

Environment variables keep sensitive details out of your source code. Your application imports the information to runtime.

Set an environment variable.

In these examples, the environment variable names are in UPPER_CASE.

export WEAVIATE_URL="http://localhost:8080"
export WEAVIATE_API_KEY="sAmPleKEY8FwELJILn0YDRG9gjy4hReqfInz"
Import an environment variable.
weaviate_url = os.getenv("WEAVIATE_URL")
weaviate_key = os.getenv("WEAVIATE_API_KEY")

gRPC timeouts

The Python client v4 and TypeScript client v3 use gRPC. The gRPC protocol is sensitive to network delay. If you encounter connection timeouts, adjust the timeout values for initialization, queries, and insertions.

import weaviate
from weaviate.classes.init import AdditionalConfig, Timeout

client = weaviate.connect_to_local(
port=8080,
grpc_port=50051,
additional_config=AdditionalConfig(
timeout=Timeout(init=30, query=60, insert=120) # Values in seconds
)
)

print(client.is_ready())

Questions and feedback

If you have any questions or feedback, let us know in the user forum.