grpclib 0.4.8


pip install grpclib

  Latest version

Released: May 04, 2025

Project Links

Meta
Author: Vladimir Magamedov
Requires Python: >=3.8

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers

License
  • OSI Approved :: BSD License

Operating System
  • OS Independent

Programming Language
  • Python
  • Python :: 3.8
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3 :: Only

Topic
  • Internet :: WWW/HTTP :: HTTP Servers
  • Software Development :: Libraries :: Python Modules
https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/7e1631d13476f1e870af0d5605b643fc14471a6d/banner-direct-single.svg

project documentation version tag downloads license

This project is based on hyper-h2 and requires Python >= 3.8.

Example

See examples directory in the project’s repository for all available examples.

Client

import asyncio

from grpclib.client import Channel

# generated by protoc
from .helloworld_pb2 import HelloRequest, HelloReply
from .helloworld_grpc import GreeterStub


async def main():
    async with Channel('127.0.0.1', 50051) as channel:
        greeter = GreeterStub(channel)

        reply = await greeter.SayHello(HelloRequest(name='Dr. Strange'))
        print(reply.message)


if __name__ == '__main__':
    asyncio.run(main())

Server

import asyncio

from grpclib.utils import graceful_exit
from grpclib.server import Server

# generated by protoc
from .helloworld_pb2 import HelloReply
from .helloworld_grpc import GreeterBase


class Greeter(GreeterBase):

    async def SayHello(self, stream):
        request = await stream.recv_message()
        message = f'Hello, {request.name}!'
        await stream.send_message(HelloReply(message=message))


async def main(*, host='127.0.0.1', port=50051):
    server = Server([Greeter()])
    # Note: graceful_exit isn't supported in Windows
    with graceful_exit([server]):
        await server.start(host, port)
        print(f'Serving on {host}:{port}')
        await server.wait_closed()


if __name__ == '__main__':
    asyncio.run(main())

Installation

$ pip3 install "grpclib[protobuf]"

Bug fixes and new features are frequently published via release candidates:

$ pip3 install --upgrade --pre "grpclib[protobuf]"

For the code generation you will also need a protoc compiler, which can be installed with protobuf system package:

$ brew install protobuf  # example for macOS users
$ protoc --version
libprotoc ...

Or you can use protoc compiler from the grpcio-tools Python package:

$ pip3 install grpcio-tools
$ python3 -m grpc_tools.protoc --version
libprotoc ...

Note: grpcio and grpcio-tools packages are not required in runtime, grpcio-tools package will be used only during code generation.

protoc plugin

In order to use this library you will have to generate special stub files using plugin provided, which can be used like this:

$ python3 -m grpc_tools.protoc -I. --python_out=. --grpclib_python_out=. helloworld/helloworld.proto
                                                    ^----- note -----^

This command will generate helloworld_pb2.py and helloworld_grpc.py files.

Plugin which implements --grpclib_python_out option should be available for the protoc compiler as the protoc-gen-grpclib_python executable which should be installed by pip into your $PATH during installation of the grpclib library.

Changed in v0.3.2: --python_grpc_out option was renamed into --grpclib_python_out.

Contributing

  • Please submit an issue before working on a Pull Request

  • Do not merge/squash/rebase your development branch while you work on a Pull Request, use rebase if this is really necessary

  • You may use Tox in order to test and lint your changes, but it is Ok to rely on CI for this matter

0.4.8 May 04, 2025
0.4.8rc2 Jul 24, 2024
0.4.8rc1 Apr 18, 2024
0.4.7 Dec 24, 2023
0.4.7rc1 Oct 28, 2023
0.4.6 Oct 02, 2023
0.4.5 Jun 22, 2023
0.4.4 May 11, 2023
0.4.3 Aug 12, 2022
0.4.3rc3 Jun 03, 2022
0.4.3rc2 Feb 02, 2022
0.4.3rc1 Nov 29, 2021
0.4.2 Aug 25, 2021
0.4.2rc2 Aug 20, 2021
0.4.2rc1 Aug 20, 2021
0.4.1 Sep 21, 2020
0.4.0 Aug 28, 2020
0.4.0rc1 Jul 27, 2020
0.3.3rc1 Jun 12, 2020
0.3.2 Jun 05, 2020
0.3.2rc2 May 30, 2020
0.3.2rc1 Mar 20, 2020
0.3.1 Nov 06, 2019
0.3.1rc2 Sep 18, 2019
0.3.1rc1 Aug 29, 2019
0.3.0 Aug 03, 2019
0.3.0rc5 Jul 10, 2019
0.3.0rc4 Jun 02, 2019
0.3.0rc3 May 23, 2019
0.3.0rc2 May 14, 2019
0.3.0rc1 Mar 31, 2019
0.2.5 May 23, 2019
0.2.4 May 03, 2019
0.2.3 Mar 31, 2019
0.2.3rc3 Mar 29, 2019
0.2.3rc2 Mar 27, 2019
0.2.3rc1 Mar 12, 2019
0.2.2 Mar 01, 2019
0.2.2rc5 Feb 25, 2019
0.2.2rc4 Feb 14, 2019
0.2.2rc3 Feb 11, 2019
0.2.2rc2 Jan 28, 2019
0.2.2rc1 Jan 25, 2019
0.2.1 Dec 15, 2018
0.2.1rc1 Oct 30, 2018
0.2.0 Oct 16, 2018
0.2.0rc2 Oct 02, 2018
0.2.0rc1 Aug 27, 2018
0.1.1 Jul 03, 2018
0.1.1rc3 Jun 23, 2018
0.1.1rc2 Jun 08, 2018
0.1.1rc1 May 29, 2018
0.1.0 Mar 30, 2018
0.1.0rc2 Dec 13, 2017
0.1.0rc1 Nov 30, 2017

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
h2 (<5,>=3.1.0)
multidict