Skip to content

Instantly share code, notes, and snippets.

@harryscholes
Created April 13, 2022 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harryscholes/d42bbd90e367fa04fb4bb568ff51e207 to your computer and use it in GitHub Desktop.
Save harryscholes/d42bbd90e367fa04fb4bb568ff51e207 to your computer and use it in GitHub Desktop.
Python asyncio gRPC client
import asyncio
import grpc
from recommender_pb2_grpc import RecommenderStub
from recommender_pb2 import RecommendRequest
async def run() -> None:
async with grpc.aio.insecure_channel('localhost:50051') as channel:
client = RecommenderStub(channel)
request = RecommendRequest()
request.tmdb_ids.extend([
44214, # Black Swan
641, # Requiem for a Dream
])
response = await client.Recommend(request)
print(response.recommendations)
if __name__ == '__main__':
asyncio.run(run())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment