Skip to main content

allure-grpc-client

A tiny helper library to send gRPC requests dynamically (via server reflection) and attach full request/response data to Allure reports. It lets you call any unary-unary gRPC method without generated stubs by providing service/method names and a JSON payload.

Key points:

  • Works with Python 3.11
  • Requires server reflection on the target gRPC service
  • Supports insecure and TLS-secured channels
  • Attaches request and response as Allure attachments

Installation

Using pip:

pip install allure-grpc-client

Using Poetry:

poetry add allure-grpc-client

Requirements

  • Python 3.11
  • A gRPC service with reflection enabled
  • Optional: Allure reporting stack to view attachments
    • allure-pytest (provided as a dependency)
    • Allure CLI to open reports

Quick start

from grpc_client import GRPClient

# Insecure channel example
client = GRPClient(address="localhost:50051")

# Secure channel example (server CA certificate path)
# client = GRPClient(address="my.secure.host:443", cert_path="/path/to/ca.crt")

# Prepare payload as a Python dict that matches the input protobuf message
payload = {
    "user_id": "12345"
}

# Optional request metadata as a sequence of (key, value)
metadata = [("authorization", "Bearer <token>")]

# Call: <package.ServiceName>/<MethodName>
response = client.send_request(
    service_name="my.package.UserService",
    method_name="GetUser",
    payload=payload,
    metadata=metadata,
)

# On success, `response` is a pretty-printed JSON string of the protobuf response.
print(response)

When run under pytest with Allure enabled, the library adds two attachments:

  • "gRPC Request" — includes an example grpcurl command and JSON payload
  • "gRPC Response" — the JSON response body

How it works

  • Uses gRPC server reflection to discover message and method descriptors at runtime.
  • Builds request/response message classes dynamically (google.protobuf).
  • Calls the method via a unary-unary channel.
  • Reports details to Allure using allure.attach.

Running with Allure

  1. Run your tests and generate Allure results:
pytest --alluredir=./allure-results
  1. Serve or open the report via Allure CLI:
allure serve ./allure-results
# or
allure generate ./allure-results -o ./allure-report --clean

Examples

  • Insecure connection:
from grpc_client import GRPClient
client = GRPClient("localhost:50051")
print(client.send_request("demo.Greeter", "SayHello", {"name": "World"}))
  • TLS with custom CA certificate:
client = GRPClient("greeter.example.com:443", cert_path="/etc/ssl/certs/greeter_ca.crt")
print(client.send_request("demo.Greeter", "SayHello", {"name": "Alice"}))
  • With metadata:
meta = [("authorization", "Bearer <token>"), ("x-request-id", "abc-123")]
client = GRPClient("localhost:50051")
print(client.send_request("demo.Greeter", "SayHello", {"name": "Bob"}, metadata=meta))

Troubleshooting

  • Reflection errors: Ensure the target service has gRPC reflection enabled.
  • SSL/TLS issues: Provide the correct root CA at cert_path. For self-signed endpoints, point to the issuing CA cert.
  • UNAVAILABLE / connection refused: Verify address is reachable and ports are open.
  • PERMISSION_DENIED / UNAUTHENTICATED: Check your metadata/credentials.

API

Only one public class is currently exposed:

  • grpc_client.GRPClient(address: str, cert_path: str | None = None)
    • Creates an insecure channel if cert_path is None, otherwise a secure channel with the provided root certs.
    • .send_request(service_name: str, method_name: str, payload: dict, metadata: Sequence[tuple[str, str]] | None = None) -> grpc.RpcError | str
      • Returns pretty JSON string on success or the grpc.RpcError instance on failure.

Note: Only unary-unary RPCs are supported at the moment.

Development

  • Python 3.11
  • Manage dependencies with Poetry
  • Linting/formatting/tests are not enforced here; feel free to adapt for your project

License

This project is licensed under the terms of the MIT License. See the LICENSE file for details.

Release files for allure-grpc-client 25.298

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for allure-grpc-client 25.298
File Size Uploaded
allure_grpc_client-25.298.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for allure-grpc-client 25.298
File Interpreter ABI Platform
allure_grpc_client-25.298-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 8.9 kB

Release files / allure_grpc_client-25.298.tar.gz

Download URL allure_grpc_client-25.298.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ea1008d2f1e6203300221e7531ca88c17259fe1091a467ec55cc7ac7c9cc3a8d
BLAKE2b-256 checksum
How to use checksums
eadc5d3e4c5533993f9f6c1e72703e48c26be3347071ab7ee79aea12c02407ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.7 Linux/6.11.0-1018-azure

Release files / allure_grpc_client-25.298-py2.py3-none-any.whl

Download URL allure_grpc_client-25.298-py2.py3-none-any.whl
Size 4.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2e8461ba3657ef4d4104a7b83f06c8ef2f99e11fc3d81436321b31398b0ceee6
BLAKE2b-256 checksum
How to use checksums
0bfc4a4aec31d9ee057ba622b4c5760bfe834746853a52d29c8cacdeab3c1d88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.7 Linux/6.11.0-1018-azure

Release history Release notifications | RSS feed

This release

25.298 This release

2 release files

25.297

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4

2 release files

1.3.11

2 release files

1.3.10

2 release files

1.3.9

2 release files

1.3.8

2 release files

1.3.7

2 release files

1.3.6

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page