grpc for Humans. grpc reflection support client
Project description
grpc_requests
##GRPC for Humans
Feature
- connect server using reflection
- no need stub class request grpc
- supprot method
- unary-unary
- unary-stream
- stream-unary
- stream-stream
install
pip install grpc_requests
example
from grpc_requests import Client
port = '50051'
host = "localhost"
endpoint = f"{host}:{port}"
client = Client.get_by_endpoint(endpoint)
print(client.service_names) # ["helloworld.Greeter"]
service = "helloworld.Greeter"
unary_unary_method = 'SayHello'
request_data = {"name": 'sinsky'} # You Don't Need Stub!
result = client.unary_unary(service, unary_unary_method, request_data)
assert dict == type(result) # result is dict Type!!! not Stub Object!
assert {"message":"Hellow sinsky"} == result
unary_stream_method = 'SayHelloGroup'
unary_stream_results = client.unary_stream(service, unary_unary_method, request_data)
assert all([dict == type(result) for result in unary_stream_results])
assert [{"message":"Hellow sinsky"}] == list(unary_stream_results)
request_datas = [request_data] # iterator
stream_unary_method = 'HelloEveryone'
result_stream_unary = client.stream_unary(service, stream_unary_method, request_datas)
assert dict == type(result) # result is dict Type!!! not Stub Object!
stream_stream_method = 'SayHelloOneByOne'
result = client.stream_stream(service, stream_stream_method,request_datas )
assert all([dict == type(result) for result in unary_stream_results])
using Stub example
from grpc_requests import Client
from helloworld_pb2 import HelloRequest
port = '50051'
host = "localhost"
endpoint = f"{host}:{port}"
client = Client.get_by_endpoint(endpoint)
print(client.service_names) # ["helloworld.Greeter"]
service = "helloworld.Greeter"
method = 'SayHello'
result = client.unary_unary(service, method, HelloRequest(name='sinsky'))
print(type(result)) # result is dict Type!!! not Stub Object!
print(result) # {"message":"Hellow sinsky"}
# or get raw response data
result = client.unary_unary(service, method, HelloRequest(name='sinsky'),raw_output=True)
print(type(result)) # HelloReply stub class
Relation Project
- homi : micro grpc framework like flask. easy to use!
Change Logs
- 0.0.1
- sync proto using reflection
- auto convert request(response) from(to) dict
- support unary-unary
- 0.0.2
- support all method type
- add request test case
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
grpc_requests-0.0.2.tar.gz
(9.1 kB
view hashes)
Built Distribution
Close
Hashes for grpc_requests-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e48b922fa0a7d07554e44f585fe8ce79025c25e0eaf09a85caadbf2e214544e |
|
MD5 | 900c355e6b729319ef8d9b7fff5bb7f4 |
|
BLAKE2b-256 | 1aad37bfb8099b68be66837e9ee2fdaee8d55bc40bbb60e119ba9a6f9a1755af |