Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

python grpc validator

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.

Metadata

Release files for grpc-proto-validator 0.1.2.dev0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for grpc-proto-validator 0.1.2.dev0
File Size Uploaded
grpc-proto-validator-0.1.2.dev0.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for grpc-proto-validator 0.1.2.dev0
File Interpreter ABI Platform
grpc_proto_validator-0.1.2.dev0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 17.3 kB

Release files / grpc-proto-validator-0.1.2.dev0.tar.gz

Download URL grpc-proto-validator-0.1.2.dev0.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
735cab0de7f4f3cf9a27c5ac371ac865baed141ed303159d54a0cc1a430271a5
BLAKE2b-256 checksum
How to use checksums
7a48317ff82b44d6a6ed97a9cae42f562ad1d091e821f81f28ec34d32921f172
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / grpc_proto_validator-0.1.2.dev0-py2.py3-none-any.whl

Download URL grpc_proto_validator-0.1.2.dev0-py2.py3-none-any.whl
Size 7.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
bcfcc8f7edaf1077e926a4a97242f5e91c2b8af7ab6e8e4c3f491529ce29644d
BLAKE2b-256 checksum
How to use checksums
3b58dd770d423655a6a8bdb60e3ce20cebca6f2586013b1de97d9835b86dad43
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.2.dev0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page