Pure-Python gRPC implementation for asyncio
===========================================
.. image:: https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/7e1631d13476f1e870af0d5605b643fc14471a6d/banner-direct-single.svg
:target: https://standforukraine.com
|project|_ |documentation|_ |version|_ |tag|_ |downloads|_ |license|_
This project is based on `hyper-h2`_ and **requires Python >= 3.7**.
.. contents::
:local:
Example
~~~~~~~
See `examples`_ directory in the project's repository for all available
examples.
Client
------
.. code-block:: python3
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
------
.. code-block:: python3
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
~~~~~~~~~~~~
.. code-block:: console
$ pip3 install "grpclib[protobuf]"
Bug fixes and new features are frequently published via release candidates:
.. code-block:: console
$ 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:
.. code-block:: console
$ brew install protobuf # example for macOS users
$ protoc --version
libprotoc ...
**Or** you can use ``protoc`` compiler from the ``grpcio-tools`` Python package:
.. code-block:: console
$ 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:
.. code-block:: console
$ 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
.. _gRPC: http://www.grpc.io
.. _hyper-h2: https://github.com/python-hyper/hyper-h2
.. _grpcio: https://pypi.org/project/grpcio/
.. _Tox: https://tox.readthedocs.io/
.. _examples: https://github.com/vmagamedov/grpclib/tree/master/examples
.. |version| image:: https://img.shields.io/pypi/v/grpclib.svg?label=stable&color=blue
.. _version: https://pypi.org/project/grpclib/
.. |license| image:: https://img.shields.io/pypi/l/grpclib.svg?color=blue
.. _license: https://github.com/vmagamedov/grpclib/blob/master/LICENSE.txt
.. |tag| image:: https://img.shields.io/github/tag/vmagamedov/grpclib.svg?label=latest&color=blue
.. _tag: https://pypi.org/project/grpclib/#history
.. |project| image:: https://img.shields.io/badge/vmagamedov%2Fgrpclib-blueviolet.svg?logo=github&color=blue
.. _project: https://github.com/vmagamedov/grpclib
.. |documentation| image:: https://img.shields.io/badge/docs-grpclib.rtfd.io-blue.svg
.. _documentation: https://grpclib.readthedocs.io/en/latest/
.. |downloads| image:: https://static.pepy.tech/badge/grpclib/month
.. _downloads: https://pepy.tech/project/grpclib
Raw data
{
"_id": null,
"home_page": "https://github.com/vmagamedov/grpclib",
"name": "grpclib",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Vladimir Magamedov",
"author_email": "vladimir@magamedov.com",
"download_url": "https://files.pythonhosted.org/packages/79/b9/55936e462a5925190d7427e880b3033601d1effd13809b483d13a926061a/grpclib-0.4.7.tar.gz",
"platform": null,
"description": "Pure-Python gRPC implementation for asyncio\n===========================================\n\n.. image:: https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/7e1631d13476f1e870af0d5605b643fc14471a6d/banner-direct-single.svg\n :target: https://standforukraine.com\n\n|project|_ |documentation|_ |version|_ |tag|_ |downloads|_ |license|_\n\nThis project is based on `hyper-h2`_ and **requires Python >= 3.7**.\n\n.. contents::\n :local:\n\nExample\n~~~~~~~\n\nSee `examples`_ directory in the project's repository for all available\nexamples.\n\nClient\n------\n\n.. code-block:: python3\n\n import asyncio\n\n from grpclib.client import Channel\n\n # generated by protoc\n from .helloworld_pb2 import HelloRequest, HelloReply\n from .helloworld_grpc import GreeterStub\n\n\n async def main():\n async with Channel('127.0.0.1', 50051) as channel:\n greeter = GreeterStub(channel)\n\n reply = await greeter.SayHello(HelloRequest(name='Dr. Strange'))\n print(reply.message)\n\n\n if __name__ == '__main__':\n asyncio.run(main())\n\nServer\n------\n\n.. code-block:: python3\n\n import asyncio\n\n from grpclib.utils import graceful_exit\n from grpclib.server import Server\n\n # generated by protoc\n from .helloworld_pb2 import HelloReply\n from .helloworld_grpc import GreeterBase\n\n\n class Greeter(GreeterBase):\n\n async def SayHello(self, stream):\n request = await stream.recv_message()\n message = f'Hello, {request.name}!'\n await stream.send_message(HelloReply(message=message))\n\n\n async def main(*, host='127.0.0.1', port=50051):\n server = Server([Greeter()])\n # Note: graceful_exit isn't supported in Windows\n with graceful_exit([server]):\n await server.start(host, port)\n print(f'Serving on {host}:{port}')\n await server.wait_closed()\n\n\n if __name__ == '__main__':\n asyncio.run(main())\n\nInstallation\n~~~~~~~~~~~~\n\n.. code-block:: console\n\n $ pip3 install \"grpclib[protobuf]\"\n\nBug fixes and new features are frequently published via release candidates:\n\n.. code-block:: console\n\n $ pip3 install --upgrade --pre \"grpclib[protobuf]\"\n\nFor the code generation you will also need a ``protoc`` compiler, which can be\ninstalled with ``protobuf`` system package:\n\n.. code-block:: console\n\n $ brew install protobuf # example for macOS users\n $ protoc --version\n libprotoc ...\n\n\n**Or** you can use ``protoc`` compiler from the ``grpcio-tools`` Python package:\n\n.. code-block:: console\n\n $ pip3 install grpcio-tools\n $ python3 -m grpc_tools.protoc --version\n libprotoc ...\n\n**Note:** ``grpcio`` and ``grpcio-tools`` packages are **not required in\nruntime**, ``grpcio-tools`` package will be used only during code generation.\n\n``protoc`` plugin\n~~~~~~~~~~~~~~~~~\n\nIn order to use this library you will have to generate special stub files using\nplugin provided, which can be used like this:\n\n.. code-block:: console\n\n $ python3 -m grpc_tools.protoc -I. --python_out=. --grpclib_python_out=. helloworld/helloworld.proto\n ^----- note -----^\n\nThis command will generate ``helloworld_pb2.py`` and ``helloworld_grpc.py``\nfiles.\n\nPlugin which implements ``--grpclib_python_out`` option should be available for\nthe ``protoc`` compiler as the ``protoc-gen-grpclib_python`` executable which\nshould be installed by ``pip`` into your ``$PATH`` during installation of the\n``grpclib`` library.\n\nChanged in v0.3.2: ``--python_grpc_out`` option was renamed into\n``--grpclib_python_out``.\n\nContributing\n~~~~~~~~~~~~\n\n* Please submit an issue before working on a Pull Request\n* Do not merge/squash/rebase your development branch while you work on a Pull\n Request, use rebase if this is really necessary\n* You may use Tox_ in order to test and lint your changes, but it is Ok to rely\n on CI for this matter\n\n.. _gRPC: http://www.grpc.io\n.. _hyper-h2: https://github.com/python-hyper/hyper-h2\n.. _grpcio: https://pypi.org/project/grpcio/\n.. _Tox: https://tox.readthedocs.io/\n.. _examples: https://github.com/vmagamedov/grpclib/tree/master/examples\n.. |version| image:: https://img.shields.io/pypi/v/grpclib.svg?label=stable&color=blue\n.. _version: https://pypi.org/project/grpclib/\n.. |license| image:: https://img.shields.io/pypi/l/grpclib.svg?color=blue\n.. _license: https://github.com/vmagamedov/grpclib/blob/master/LICENSE.txt\n.. |tag| image:: https://img.shields.io/github/tag/vmagamedov/grpclib.svg?label=latest&color=blue\n.. _tag: https://pypi.org/project/grpclib/#history\n.. |project| image:: https://img.shields.io/badge/vmagamedov%2Fgrpclib-blueviolet.svg?logo=github&color=blue\n.. _project: https://github.com/vmagamedov/grpclib\n.. |documentation| image:: https://img.shields.io/badge/docs-grpclib.rtfd.io-blue.svg\n.. _documentation: https://grpclib.readthedocs.io/en/latest/\n.. |downloads| image:: https://static.pepy.tech/badge/grpclib/month\n.. _downloads: https://pepy.tech/project/grpclib",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "Pure-Python gRPC implementation for asyncio",
"version": "0.4.7",
"project_urls": {
"Homepage": "https://github.com/vmagamedov/grpclib"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "79b955936e462a5925190d7427e880b3033601d1effd13809b483d13a926061a",
"md5": "60ce203e5b9f95de3d7e5721dbce2bd9",
"sha256": "2988ef57c02b22b7a2e8e961792c41ccf97efc2ace91ae7a5b0de03c363823c3"
},
"downloads": -1,
"filename": "grpclib-0.4.7.tar.gz",
"has_sig": false,
"md5_digest": "60ce203e5b9f95de3d7e5721dbce2bd9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 61254,
"upload_time": "2023-12-24T17:47:41",
"upload_time_iso_8601": "2023-12-24T17:47:41.572061Z",
"url": "https://files.pythonhosted.org/packages/79/b9/55936e462a5925190d7427e880b3033601d1effd13809b483d13a926061a/grpclib-0.4.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-24 17:47:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "vmagamedov",
"github_project": "grpclib",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "grpclib"
}