A simple gRPC server just like Flask.
Project description
Mask
A gRpc server just like Flask
.
Install
Mask
support pypi packages, you can simply install by:
pip install mask
Document
Mask
manual could be found at: https://mask.readthedocs.io/en/latest
A Simple Example
This is very easy to use Mask
in your project.
from mask import Mask
from mask.parse import pre, Rule
app = Mask(__name__)
rule = {
"name": Rule(type=str, gte=2, dest="Name")
}
@app.route(method="SayHello", service="Hello")
def say_hello(request, context):
""" Handler SayHello request
"""
params = pre.parse(rule=rule, request=request, context=context)
return HelloResponse(message="Hello Reply: %s" % params["Name"])
if __name__ == "__main__":
app.run(host="0.0.0.0", port=1020)
Service
Mask
support Service
to organize a group of route which is likely with Blueprint
in Flask
.
# 3p
from mask import Mask, Service
from mask.parse import pre, Rule
# project
from examples.protos.hello_pb2 import HelloResponse
app = Mask(__name__)
app.config["REFLECTION"] = True
# Bind service to application
service = Service(name="Hello")
app.register_service(service)
rule = {
"name": Rule(type=str, gte=2, dest="Name")
}
# Service route
@service.route(method="SayHello")
def say_hello_handler(request, context):
""" Handler SayHello request
"""
params = pre.parse(rule=rule, request=request, context=context)
return HelloResponse(message="Hello Reply: %s" % params["Name"])
if __name__ == "__main__":
app.run(host="0.0.0.0", port=1020)
Middleware
Mask
support middleware to hook before request and after request.
# 3p
from mask import Mask
# project
from examples.protos.hello_pb2 import HelloResponse
app = Mask(__name__)
app.config["REFLECTION"] = True
def before_request(request, context):
print(request.name)
def after_request(response):
print(response.message)
app.before_request(before_request)
app.after_request(after_request)
@app.route(method="SayHello", service="Hello")
def say_hello_handler(request, context):
""" Handler SayHello request
"""
return HelloResponse(message="Hello Reply: %s" % request.name)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=1020)
Coffee
Please give me a cup of coffee, thank you!
BTC: 1657DRJUyfMyz41pdJfpeoNpz23ghMLVM3
ETH: 0xb098600a9a4572a4894dce31471c46f1f290b087
Links
- Documentaion: https://mask.readthedocs.io/en/latest
- Release: https://github.com/Eastwu5788/Mask/releases
- Code: https://github.com/Eastwu5788/Mask
- Issue tracker: https://github.com/Eastwu5788/Mask/issues
- Test status: https://coveralls.io/github/Eastwu5788/Mask
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mask-1.0.0.tar.gz
(27.2 kB
view details)
File details
Details for the file mask-1.0.0.tar.gz
.
File metadata
- Download URL: mask-1.0.0.tar.gz
- Upload date:
- Size: 27.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 233c478ede1f5185ecc4c235e21ac30ad11aa23440aa37bac82d1e51d6ba6fbd |
|
MD5 | faa4c05a652a432c1d4c95c1f6d6b6ba |
|
BLAKE2b-256 | 1da88ae799980804328753357bc956de1367284abb35184f4404c5d366b46a40 |