gRPC-WSGI
A gRPC-Web implementation based on Python's WSGI standard.
Why?
gRPC has a lot going for it but is awkward to use in some environments. gRPC-WSGI makes it easy to integrate gRPC when you need to use HTTP/1.1 load balancers or proxies, or want to integrate gRPC into existing services such as Django or Flask apps that speak a different protocol most of the time.
There are two main capabilities this implementation has over Google's.
- HTTP/1.1 compatability via gRPC-Web, even for unary_stream RPCs using protobuf. Without the need for a sidecar proxy process like Envoy.
- Run gRPC and other HTTP stuff on the same socket.
How?
gRPC-WSGI is designed to require minimal changes to an existing WSGI or gRPC code base.
Server
Normally a WSGI application (such as your favourite Django app) will call something such as
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
in it somewhere so that your application server (uWSGI, Gunicorn etc) knows where your code is.
To add gRPC-WSGI to an application like the above all you need to do to enable it is this.
from django.core.wsgi import get_wsgi_application
from grpcWSGI.server import grpcWSGI
application = get_wsgi_application()
application = grpcWSGI(application)
The grpcWSGI application object also happens to be compatible with the normal grpc.Server interface. So all you need to do actually attach your RPCs and start making calls to your new service is the usual gRPC setup of e.g.
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), application)
And now you have a combined HTTP/1.1 Django + gRPC application all under a single port.
Client
Setting up a client is similarly very simple and similar to standard gRPC calls.
Instead of using gRPCs native insecure_channel API we have grpcWSGI.client.insecure_web_channel instead which provides a https://github.com/kennethreitz/requests powered client channel to a gRPC-Web server. e.g.
import gRPCWSGI.client
with grpcWSGI.client.insecure_web_channel(
f"http://localhost:8080"
) as channel:
stub = helloworld_pb2_grpc.GreeterStub(channel)
print(stub.SayHello("world"))
TODO
- Error handling
- Compression?
- Benchmarks?
- Clean up the CORS stuff.
- StreamStream/StreamUnary RPCs?
- Retries, caching and other client options.
- Quality of life integrations for Django, Flask etc.
- application/grpc-web-text support? Do I care about IE10? JSON is potentially faster than Protobuf sometimes...
- aiohttp / grpc-aiohttp / ASGI integration?
- MyPy annotations? https://github.com/dropbox/mypy-protobuf Already makes this pretty OK.
- Use more of the ABCs and other standard stuff from the grpc package
- Make support for chunked encoding vaguely reliable
- Some kind of metaclass magic to make it easier to ensure you've actually implemented a servers interface
Metadata
Release files for grpcWSGI 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| grpcWSGI-0.0.4.tar.gz | 7.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| grpcWSGI-0.0.4-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 19.8 kB
Release files / grpcWSGI-0.0.4.tar.gz
| Download URL | grpcWSGI-0.0.4.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5dd70c83b6b3ba44f711733c099d7a323fe5815d5d032747a594348d16ab894a
|
|
BLAKE2b-256 checksum How to use checksums |
a3973cfe9023257aee9b09d5cdb3bafe9cdba28ff141dd13d1fee94c318a0191
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Release files / grpcWSGI-0.0.4-py2.py3-none-any.whl
| Download URL | grpcWSGI-0.0.4-py2.py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0f59db87573f3954496450fd85464f9f3f54caf7b6b9a2824ad521ea957c9d32
|
|
BLAKE2b-256 checksum How to use checksums |
709603810df4f733113e7e790b2a6f07074db2e247dde52d8c9de56d723b9eb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Security for grpcWSGI 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.