Skip to main content

grpc proto validator.

Project description

plugin of validate request field for python grpc server.

https://travis-ci.com/v1c77/py_grpc_validator.svg?branch=master https://codecov.io/gh/v1c77/py_grpc_validator/branch/master/graph/badge.svg
TODO:
  • type hint for different field type.(such as only string field can do a string length check.)

  • test case & Makefile.

  • a cli to help protoc with validator.proto.

  • anymore bugs or improves?

How To

  1. install

pip install grpc-proto-validator

2. copy validator.proto to your project proto path and do protoc.(TODO a cli help to copy or build proto.)

The validator.proto is included in this package, you can find it in python site-packages path.

A example on how to generate the grpc files:

$ python -m grpc_tools.protoc \
  --proto_path={/path/to/validator/proto} \
  --proto_path={/path/to/your/project/proto} \
  --python_out={/path/to/project/src} \
  --grpc_python_out={/path/to/project/src} \
  path/to/your.proto
  1. change your service and *_pb2 code.

To avoid protobuf import error, change one line in the generated python file(like hello_bro_pb2.py).

from:

import validator_pb2 as validator__pb2

to:

import grpc_proto_validator.validator_pb2 as validator__pb2.

Then create service with validator:

import six
from grpc_validator.validator import ValidateMetaclass

class YourService(six.with_metaclass(ValidateMetaclass,
                         YourService_pb2_grpc.YourServiceServer)):

    def behaviour1(self, request, context)
        ...

Also, you can select individual service handler to do the field check:

from grpc_validator.validator import validator_wrap


class YourService(YourService_pb2_grpc.YourServiceServer):

    def behaviour(self, request, context):
        """request will not be validated."""
        ...

    @validator_wrap
    def behaviour2(self, request, context):
        ...

Notice

Someone has used go-proto-validator before will notice that I almost reuse its proto file which make it easier to co-work with our golang service team.

But please don’t mix these two proto files. !!!THEY ARE NOT IN COMMON USE!!!

Any help or idea is favourably receive. Please just make a issue.

LICENSE

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grpc-proto-validator-0.1.2.dev0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grpc_proto_validator-0.1.2.dev0-py2.py3-none-any.whl (7.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file grpc-proto-validator-0.1.2.dev0.tar.gz.

File metadata

  • Download URL: grpc-proto-validator-0.1.2.dev0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.15

File hashes

Hashes for grpc-proto-validator-0.1.2.dev0.tar.gz
Algorithm Hash digest
SHA256 735cab0de7f4f3cf9a27c5ac371ac865baed141ed303159d54a0cc1a430271a5
MD5 29e9a56ceab689c14ac48fcb1d14255e
BLAKE2b-256 7a48317ff82b44d6a6ed97a9cae42f562ad1d091e821f81f28ec34d32921f172

See more details on using hashes here.

File details

Details for the file grpc_proto_validator-0.1.2.dev0-py2.py3-none-any.whl.

File metadata

  • Download URL: grpc_proto_validator-0.1.2.dev0-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.15

File hashes

Hashes for grpc_proto_validator-0.1.2.dev0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bcfcc8f7edaf1077e926a4a97242f5e91c2b8af7ab6e8e4c3f491529ce29644d
MD5 c0b3cb1c95e803e8a1a5837284a7e501
BLAKE2b-256 3b58dd770d423655a6a8bdb60e3ce20cebca6f2586013b1de97d9835b86dad43

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page