The `opensearch-protobufs` library provides Protocol Buffer definitions and generated Python code for interacting with OpenSearch's gRPC APIs. It serves as a downstream consumer of the `opensearch-api-specification`, packaging pre-generated code to simplify client-server communication for various OpenSearch projects. The library is actively maintained with frequent releases, offering a high-performance alternative to traditional REST APIs through binary serialization and gRPC.
pip install opensearch-protobufsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a simple `SearchRequest` using the generated protobuf classes, establish an insecure gRPC channel, and send the request to an OpenSearch gRPC endpoint. It then processes the `SearchResponse`. Remember to configure your `OPENSEARCH_GRPC_TARGET` and use secure channels in production environments. An OpenSearch instance with gRPC transport enabled (e.g., in `opensearch.yml` with `aux.transport.types: [transport-grpc]`) is required for this code to function against a live service.
Always consult the `opensearch-protobufs` GitHub repository and OpenSearch documentation's gRPC section, especially the compatibility matrix (`COMPATIBILITY.md`), when upgrading OpenSearch or `opensearch-protobufs` versions. Pin your `opensearch-protobufs` version carefully.
Ensure all document content intended for fields like `doc` or `source` is first serialized (e.g., to JSON string), then encoded to bytes, and finally Base64 encoded before being assigned to the protobuf field. For example: `base64.b64encode(json.dumps({'field': 'value'}).encode('utf-8'))`.Install `grpcio` alongside `opensearch-protobufs`: `pip install opensearch-protobufs grpcio`. If generating code, also install `grpcio-tools`: `pip install opensearch-protobufs grpcio grpcio-tools`.
Refer to the `COMPATIBILITY.md` file in the `opensearch-protobufs` GitHub repository to determine the correct client version for your OpenSearch cluster version. Upgrade both components in sync as recommended.
Change the import statement to explicitly import the message from the `schemas` submodule: `from opensearch.protobufs.schemas import SearchRequest`.
Ensure the OpenSearch instance is running and accessible. Verify that the `transport-grpc` plugin is installed and enabled in your `opensearch.yml` configuration (e.g., `aux.transport.types: [experimental-transport-grpc]`). Confirm the gRPC client is configured with the correct host and port for the OpenSearch gRPC endpoint.
Consult the `opensearch-protobufs` library documentation or the source `.proto` files to verify the correct gRPC method names (e.g., `SearchServiceStub.Search`). Ensure the method name matches exactly, including case.