python-cygrpc
Micro-Framwork for gRPC with REST expose support.
installation
- Using pip
pip install cygrpc
- Using git repository
git+https://github.com/cuemby/python-cygrpc.git#egg=cygrpc
Usage
Server
Params:
- host : str = server host, by default is '0.0.0.0'
- port : int = server port for listen. by default is 50051
- max_threads : int = set threads workers for server, by default is 10
- interceptors: tuple(InterceptorImplementation) = server interceptors middlewares. by default is None.
- http_port: int = port for http gateway
if you decide used all values by default, you can setup the server in less lines
from cygrpc.server import Server
server = Server()
server.add_service(calculator_api_pb2_grpc, ServiceImpl)
server.start()
Example using all params:
from cygrpc.server import Server
# Initialization of server definition, 'host', 'port', 'max_threads' has be optionals.
# By default the __init__ function set the same values. if don't you wanna set interceptors only remove the param
server = Server(host="0.0.0.0", port=50051, max_threads=10, interceptors=(MyAuthInterceptor(),))
# attach service to server, repeat for multiple services
server.add_service(calculator_api_pb2_grpc, ServiceImpl)
# finally start server.
server.start()
Implement service
The implementation is the same.
# import rest decorator
from cygrpc.gateway.http import rest
class ServiceImpl(calculator_api_pb2_grpc.CalculatorAPIServicer):
"""
Service logic implementation.
"""
def Sum(self, request, context):
total = 0
for addend in request.addends:
total += addend
response = pb.SumResponse(sum=total)
return response
rest route
for add rest route add the decorator @rest to method definition:
# import rest decorator
from cygrpc.gateway.http import rest
class ServiceImpl(calculator_api_pb2_grpc.CalculatorAPIServicer):
"""
Service logic implementation.
"""
@rest("/v1/calculator/sum", method="POST")
def Sum(self, request, context):
total = 0
for addend in request.addends:
total += addend
response = pb.SumResponse(sum=total)
return response
Interceptors
- Base Interceptor : Base interceptor implementation for create your custom interceptor
from cygrpc.middleware import CyGrpcInterceptor
class CustomInterceptor(CyGrpcInterceptor):
def intercept_service(self, continuation, handler_call_details):
# for continue to method implementation
return self.on_success(continuation, handler_call_details)
# for terminate request
return self.on_failed(grpc.StatusCode.UNAUTHENTICATED, "Validate authentication failed.")
- Authentication interceptor: provider a base for authentication middleware interceptor
from cygrpc.middleware.auth import CyGrpcAuthInterceptor
class MyAuthInterceptor(CyGrpcAuthInterceptor):
def auth_process(self, continuation, handler_call_details):
""""
..... my auth validation process ....
"""
return True
Authors:
- Fabio Moreno fabio.moreno@cuemby.com
Metadata
Release files for cygrpc 1.0.4.post6
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 | Actions |
|---|---|---|---|---|
| cygrpc-1.0.4.post6.tar.gz | 16.2 kB | Without provenance | Details for cygrpc-1.0.4.post6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cygrpc-1.0.4.post6-py3-none-any.whl | Python 3 | none | any | Details for cygrpc-1.0.4.post6-py3-none-any.whl |
Total release size: 37.4 kB
Release files / cygrpc-1.0.4.post6.tar.gz
| Download URL | cygrpc-1.0.4.post6.tar.gz |
|---|---|
| Size | 16.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6f151e2a433337a8a571b0ec165a8dc4e1de3d1c0587a5ee565d26b60d058c6
|
|
BLAKE2b-256 checksum How to use checksums |
a935192a7de8ba422b63b477274b3521c6663b9a7570e98b0a7ed1920d8d74fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9
|
Release files / cygrpc-1.0.4.post6-py3-none-any.whl
| Download URL | cygrpc-1.0.4.post6-py3-none-any.whl |
|---|---|
| Size | 21.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
43f69fde7f632f2ef22a68a6ae548ca64b9018eca595231afb87e2ad3e6a3407
|
|
BLAKE2b-256 checksum How to use checksums |
99c2560f21c36493d699f2d78245c8d49490d3bfed03df824aa83cc2a5160d96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9
|
Security for cygrpc 1.0.4.post6
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.