No project description provided
Project description
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
- Run your tests and generate Allure results:
pytest --alluredir=./allure-results
- 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
addressis 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_pathis 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.RpcErrorinstance on failure.
- Returns pretty JSON string on success or the
- Creates an insecure channel if
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file allure_grpc_client-25.298.tar.gz.
File metadata
- Download URL: allure_grpc_client-25.298.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.7 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea1008d2f1e6203300221e7531ca88c17259fe1091a467ec55cc7ac7c9cc3a8d
|
|
| MD5 |
223b0622f6d9e1b327280fccfa8aee8c
|
|
| BLAKE2b-256 |
eadc5d3e4c5533993f9f6c1e72703e48c26be3347071ab7ee79aea12c02407ef
|
File details
Details for the file allure_grpc_client-25.298-py2.py3-none-any.whl.
File metadata
- Download URL: allure_grpc_client-25.298-py2.py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.7 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e8461ba3657ef4d4104a7b83f06c8ef2f99e11fc3d81436321b31398b0ceee6
|
|
| MD5 |
d56c34126114d78e0f76df7203e94043
|
|
| BLAKE2b-256 |
0bfc4a4aec31d9ee057ba622b4c5760bfe834746853a52d29c8cacdeab3c1d88
|