Skip to content

Commit

Permalink
[Python Support] Update Docs (#262)
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Kothari <akothari@lyft.com>
  • Loading branch information
kothariaditya authored and rodaine committed Aug 27, 2019
1 parent 9c68018 commit b2e4ad3
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ make build
- `gogo` for [gogo proto](https://github.com/gogo/protobuf) (experimental)
- `cc` for c++ (partially implemented)
- `java`

Support for `python` is planned.
- `python`

### Examples

Expand Down Expand Up @@ -213,6 +212,31 @@ clientStub = clientStub.withInterceptors(new ValidatingClientInterceptor(index))
serverBuilder.addService(ServerInterceptors.intercept(svc, new ValidatingServerInterceptor(index)));
```

#### Python

Since Python is a dynamically typed language, it works with JIT code generation. So protoc does not need to be run to generate code.

The file `validate/validator.py` has a `validate()` method which needs to be run with an instance of the proto you are validating.

You must install all the dependencies in the `requirements.txt` before running the validator.

To run `validate()`, do the following:
```
from validator import validate, FailedValidation
p = Person()
validate(p) # This should either return None or raise a ValidationFailed exception.
```

To see what code has been generated and run, you can do the following:
```
from validator import validate, print_validate, FailedValidation
p = Person()
validate(p)
printer = print_validate(p)
```

## Constraint Rules

[The provided constraints](validate/validate.proto) are modeled largerly after those in JSON Schema. PGV rules can be mixed for the same field; the plugin ensures the rules applied to a field cannot contradict before code generation.
Expand Down

0 comments on commit b2e4ad3

Please sign in to comment.