diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 3a5c65901..7f2fe8833 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -8,7 +8,7 @@ on: - '**' paths-ignore: - docs/** - - README.rst + - README.md - LICENSE.md - publishing.md pull_request: diff --git a/README.md b/README.md new file mode 100644 index 000000000..a4dde5e81 --- /dev/null +++ b/README.md @@ -0,0 +1,183 @@ +# Weaviate Python client Weaviate logo + +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") + + 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. +# 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 +pytest -n auto --dist loadgroup integration +./ci/stop_weaviate.sh +``` + +## License + +BSD-3-Clause. See [LICENSE](https://github.com/weaviate/weaviate-python-client/blob/main/LICENSE). diff --git a/README.rst b/README.rst deleted file mode 100644 index 1f1fc366f..000000000 --- a/README.rst +++ /dev/null @@ -1,59 +0,0 @@ -Weaviate python client -====================== -.. image:: https://raw.githubusercontent.com/weaviate/weaviate/19de0956c69b66c5552447e84d016f4fe29d12c9/docs/assets/weaviate-logo.png - :width: 180 - :align: right - :alt: Weaviate logo - -.. image:: https://github.com/weaviate/weaviate-python-client/actions/workflows/.github/workflows/main.yaml/badge.svg?branch=main - :target: https://github.com/weaviate/weaviate/actions/workflows/.github/workflows/pull_requests.yaml - :alt: Build Status - -.. image:: https://badge.fury.io/py/weaviate-client.svg - :target: https://badge.fury.io/py/weaviate-client - :alt: PyPI version - -.. image:: https://readthedocs.org/projects/weaviate-python-client/badge/?version=latest - :target: https://weaviate-python-client.readthedocs.io/en/latest/?badge=latest - :alt: Documentation Status - -A python native client for easy interaction with a Weaviate instance. - -The client is tested for python 3.11 and higher. - -Visit the official `Weaviate `_ website for more information about the Weaviate and how to use it in production. - -Client Versions ---------------- -We currently support the following versions client versions: - -- 4.X: actively supported -- 3.X: deprecated, receives only critical bug fixes and dependency updates - - -Articles --------- - -Here are some articles on Weaviate: - -- `Semantic Search Queries Return More Informed Results `_ -- `Getting Started with Weaviate Python Library `_ -- `A sub-50ms neural search with DistilBERT and Weaviate `_ - -Documentation -------------- - -- `Weaviate Python client overview `_. -- `Weaviate documentation `_. -- `Additional reference documentation `_ - -Support -------- - -- Use our `Community Forum `_ for support or any other question. -- Use the ``weaviate`` tag on `StackOverflow `_ for questions. -- For bugs or problems, submit a GitHub `issue `_. - -Contributing ------------- -To contribute, read `How to Contribute `_. diff --git a/setup.cfg b/setup.cfg index 6b3daa241..65804457d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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