Watch Star Fork

灵剑2012 / aiogrpcPythonApache-2.0

与超过 200 万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
asyncio wrapper for
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading... 2.32 KB


Build Status PyPI

asyncio wrapper for Currently, only client-side interfaces are supported.


aiogrpc has exactly the same interface as (, except:

  • All callbacks are called with call_soon_threadsafe() to run in the same thread with the event loop
  • All futures are asyncio futures (i.e. awaitable)
  • All blocking interfaces (__call__ for unary methods, code(), details(), ...) become coroutines
  • Stream input/output are async iterators


  1. Compile your proto file with protoc to generate stub files

  2. Use the stub files with aiogrpc.Channel, instead of grpc.Channel:

    from aiogrpc import insecure_channel
    import asyncio
    from mystub import MyStub
    channel = insecure_channel('ipv4:///')
    mystub = MyStub(channel)
    async def test_call():
        return await mystub.mymethod(...)
    async def test_call_stream():
        async for v in mystub.my_stream_method(...):


Same as the original, balancing (fail over) between multiple servers are supported:

  1. Use multiple IPv4 or IPv6 addresses for balancing - use target like: "ipv4:///,," or "ipv6:///[1::2]:9999,[1::3]:9999,[1::4]:9999"

  2. Specify ONE DNS name which resolves to multiple addresses. GRPC will balance between the resolved addresses, and try to update the resolving result in interval. Example: "dns:///myserver:9999"

Notice that you cannot mix up IPv4, IPv6 and DNS addresses; only addresses with the same type can be balanced. Also, when using DNS target, only one DNS name can be specified.

The default load balancing strategy is "pick_first" (fail-over). Set "grpc.lb_policy_name" option to "round_robin" for round-robin load balancing: channel = insecure_channel('ipv4:///,,', [('grpc.lb_policy_name', 'round_robin')])

Copyright Notice

All code are published under Apache 2.0 License

Some code and docstrings are modified from (

项目点评 ( 1 )


8_float_left_people 8_float_left_close