I'm able to send requests to one of our gRPC-enabled, reflection-enabled server using grpcurl with the following syntax:
grpcurl --plaintext -d '{"test_input": "Test 1 2 3", "config": { "max_results": 3 }}' localhost:6565 myorg.myproject.v1alpha6.MyService.MyStub
This does not require knowledge of the protos from grpcurl. And it's just perfect because I'm using it in a test script that I want to keep as simple as possible.
I've been able to leverage that to write a very simple python script:
import json
import subprocess
input = { "test_input": "Test 1 2 3", "config": { "max_results": 3 } }
result = subprocess.check_output(['grpcurl', '--plaintext', '-d', json.dumps(input), 'localhost:6565', 'MyStub'])
dict_result = json.loads(result)
But I'm not too happy about having to call an external process.
All the documentations I found on the internet require downloading the protos and their dependencies and compile them using protoc
. I can do that and this is not the object of the question. The goal here it to use Python to exchange with the server using JSON and without downloading the proto. Just like it's done with grpcurl.
Can this be done using python only ?