Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- '**'
paths-ignore:
- docs/**
- README.rst
- README.md
- LICENSE.md
- publishing.md
pull_request:
Expand Down
183 changes: 183 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# Weaviate Python client <img alt='Weaviate logo' src='https://weaviate.io/img/site/weaviate-logo-light.png' width='148' align='right' />

The official Python client for [Weaviate](https://weaviate.io), the open-source vector database.

[![PyPI](https://img.shields.io/pypi/v/weaviate-client)](https://pypi.org/project/weaviate-client/)
[![Build Status](https://github.com/weaviate/weaviate-python-client/actions/workflows/main.yaml/badge.svg?branch=main)](https://github.com/weaviate/weaviate-python-client/actions/workflows/main.yaml)
[![Documentation Status](https://app.readthedocs.org/projects/weaviate-python-client/badge/?version=latest)](https://weaviate-python-client.readthedocs.io/en/latest/)
[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue)](https://github.com/weaviate/weaviate-python-client/blob/main/LICENSE)

## Packages

| Package | Use it for | Runtime |
| --- | --- | --- |
| [`weaviate-client`](https://pypi.org/project/weaviate-client/) | Apps, scripts and data ingestion. Has a sync client and an async client. Talks to Weaviate over REST and gRPC. | CPython |
| [`weaviate-client-web`](https://pypi.org/project/weaviate-client-web/) | Running the async client in a browser page, a marimo notebook or a Web Worker. Talks to Weaviate over REST and gRPC-Web. Install it through the `grpc-web` extra. | Pyodide (WebAssembly) |

## Install

```bash
pip install -U weaviate-client
# or: uv add weaviate-client
```

For Weaviate Agents such as the Query Agent, install the `agents` extra instead: `pip install -U "weaviate-client[agents]"`. It adds the companion package [`weaviate-agents`](https://pypi.org/project/weaviate-agents/).

`weaviate-client` needs Python 3.11 or later.

## Quickstart

This example needs a local Weaviate with no vectorizer module. See [Run Weaviate with Docker](https://docs.weaviate.io/deploy/installation-guides/docker-installation). The example brings its own vectors and searches with `near_vector`.

```python
import weaviate
from weaviate.classes.config import Configure, DataType, Property
from weaviate.classes.data import DataObject
from weaviate.classes.query import MetadataQuery

with weaviate.connect_to_local() as client:
if client.collections.exists("Article"):
client.collections.delete("Article")
Comment thread
g-despot marked this conversation as resolved.
Resolved

articles = client.collections.create(
name="Article",
properties=[Property(name="title", data_type=DataType.TEXT)],
vector_config=Configure.Vectors.self_provided(),
)

articles.data.insert_many([
DataObject(properties={"title": "Intro to vector search"}, vector=[0.1, 0.9, 0.2]),
DataObject(properties={"title": "Tuning HNSW indexes"}, vector=[0.8, 0.1, 0.3]),
])

result = articles.query.near_vector(
near_vector=[0.2, 0.8, 0.1],
limit=1,
return_metadata=MetadataQuery(distance=True),
)

for obj in result.objects:
print(obj.properties["title"], obj.metadata.distance)
```

To connect to Weaviate Cloud, replace the `connect_to_local()` call. Set `WEAVIATE_URL` and `WEAVIATE_API_KEY` in your environment first.

```python
import os

import weaviate
from weaviate.classes.init import Auth

with weaviate.connect_to_weaviate_cloud(
cluster_url=os.environ["WEAVIATE_URL"],
auth_credentials=Auth.api_key(os.environ["WEAVIATE_API_KEY"]),
) as client:
print(client.is_ready())
```

## Async

The client also has an async API. The `use_async_with_*` helpers create an async client, and `async with` connects it and closes it. This example queries the collection from the quickstart.

```python
import asyncio

import weaviate


async def main():
async with weaviate.use_async_with_local() as client:
articles = client.collections.use("Article")
result = await articles.query.near_vector(near_vector=[0.2, 0.8, 0.1], limit=1)
for obj in result.objects:
print(obj.properties["title"])


asyncio.run(main())
```

See the [async client docs](https://docs.weaviate.io/weaviate/client-libraries/python/async).

## Embedded Weaviate

Embedded Weaviate downloads a Weaviate binary and starts it from your Python process. It runs on Linux and macOS. It does not run on Windows.

```python
import weaviate

with weaviate.connect_to_embedded() as client:
print(client.is_ready())
```

See [Embedded Weaviate](https://docs.weaviate.io/deploy/installation-guides/embedded).

## Use in the browser (Pyodide)

`weaviate-client-web` runs the async client under [Pyodide](https://pyodide.org), a Python runtime for the browser. Use it in browser pages, marimo notebooks and Web Workers. Install it through the `grpc-web` extra of `weaviate-client`, as in the example below. For details, see the [web client docs](https://docs.weaviate.io/weaviate/client-libraries/python/web-client).

```python
import micropip

await micropip.install("weaviate-client[grpc-web]")

import weaviate

client = weaviate.use_async_with_local(port=8080) # The HTTP port. gRPC-Web uses it too.
await client.connect()
await client.close()
```

The example uses top-level `await`, which Pyodide supports. Run it in a marimo notebook cell or in another Pyodide environment. It does not run under CPython.

Keep these points in mind:

- `weaviate-client-web` needs Weaviate 1.38.3 or later.
- gRPC requests use gRPC-Web on the HTTP host and port, at the `/v1/grpc-web` path. You do not configure a separate gRPC port. If you use `use_async_with_custom()`, set its gRPC host, port and secure values to the same values as the HTTP ones. The client replaces other values with the HTTP ones and shows a warning.
- Only the async client works. The sync client and Embedded Weaviate are not available.
- Server-side batching is not available. `client.batch.stream()` and `collection.batch.stream()` raise an error. Use `collection.data.insert_many()` instead.
- Anyone who loads your page can read the keys in its code. Never ship an admin key to a browser. Use a read-only API key that has only the [RBAC](https://docs.weaviate.io/deploy/configuration/authorization) permissions your app needs.
- Browser requests are subject to CORS, so the Weaviate server must allow your page's origin. On Weaviate Cloud, turn on the `Allow all CORS origins` setting for the database. See [default settings](https://docs.weaviate.io/cloud/manage-clusters/default-settings).

## Compatibility

This client works with Weaviate 1.32.0 and later. It raises an error when you connect to an older server. To check which Weaviate versions a client release supports, see the [version table](https://docs.weaviate.io/weaviate/client-libraries/python#releases) in the docs.

## Migrating from an older version

If you are moving from the v3 client (`weaviate.Client`), follow the [v3 to v4 migration guide](https://archive.docs.weaviate.io/weaviate/client-libraries/python/v3_v4_migration).

## Documentation

- [Python client docs](https://docs.weaviate.io/weaviate/client-libraries/python)
- [API reference](https://weaviate-python-client.readthedocs.io/en/latest/)
- [Changelog](https://github.com/weaviate/weaviate-python-client/blob/main/docs/changelog.rst)

## Support

- [Weaviate Forum](https://forum.weaviate.io) for questions.
- [GitHub Issues](https://github.com/weaviate/weaviate-python-client/issues) for bugs and feature requests.

## Contributing

Read the [contributing guide](https://github.com/weaviate/weaviate-python-client/blob/main/CONTRIBUTING.md) before you open a pull request.

To set up a development environment and run the tests:

```bash
pip install -r requirements-devel.txt -r requirements-test.txt
pip install -e .

# Unit and mock tests. These need no Weaviate.
pytest test mock_tests

# Integration tests. These start the test stack in Docker, run the tests, then stop the stack.
# <version> is a Weaviate release without the leading "v".
# Starts several containers on ports 8075-8093, 9999, 10000, 48001, 48003 and 50051-50065
./ci/start_weaviate.sh <version>
pytest -n auto --dist loadgroup integration
./ci/stop_weaviate.sh <version>
```

## License

BSD-3-Clause. See [LICENSE](https://github.com/weaviate/weaviate-python-client/blob/main/LICENSE).
59 changes: 0 additions & 59 deletions README.rst

This file was deleted.

12 changes: 10 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
[metadata]
name = weaviate-client
description = A python native Weaviate client
long_description = file: README.rst
long_description_content_type = text/x-rst; charset=UTF-8
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/weaviate/weaviate-python-client
author = Weaviate
author_email = hello@weaviate.io,
license_files = LICENSE
license = BSD 3-clause
classifiers =
Operating System :: OS Independent
Programming Language :: Python :: 3
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13
Programming Language :: Python :: 3.14
Programming Language :: Python :: 3.15
project_urls =
Documentation = https://weaviate-python-client.readthedocs.io
Source = https://github.com/weaviate/weaviate-python-client
Expand Down
Loading