# Protoc-gen-validate (PGV)
While protocol buffers effectively guarantee the types of structured data,
they cannot enforce semantic rules for values. This package is a python implementation
of [protoc-gen-validate][pgv-home], which allows for runtime validation of various
semantic assertions expressed as annotations on the protobuf schema. The syntax for all available annotations is
in `validate.proto`. Implemented Python annotations are listed in the [rules comparison][rules-comparison].
### Example
```python3
from entities_pb2 import Person
from protoc_gen_validate.validator import validate, ValidationFailed, validate_all
p = Person(name="Foo")
try:
validate(p)
except ValidationFailed as err:
print(err) # p.id is not greater than 999
try:
validate_all(p)
except ValidationFailed as err:
print(err)
# p.id is not greater than 999
# p.email is not a valid email
# p.name pattern does not match ^[^[0-9]A-Za-z]+( [^[0-9]A-Za-z]+)*$
# home is required.
```
[pgv-home]: https://github.com/envoyproxy/protoc-gen-validate
[rules-comparison]: https://github.com/envoyproxy/protoc-gen-validate/blob/main/rule_comparison.md
Raw data
{
"_id": null,
"home_page": "https://github.com/bufbuild/protoc-gen-validate",
"name": "protoc-gen-validate",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "Buf",
"author_email": "dev@buf.build",
"download_url": "https://files.pythonhosted.org/packages/3f/a5/23d7cb04f7e714ed854e5497247806d97db20f39c4268df26ed66816b2d6/protoc-gen-validate-1.0.4.tar.gz",
"platform": null,
"description": "# Protoc-gen-validate (PGV)\nWhile protocol buffers effectively guarantee the types of structured data, \nthey cannot enforce semantic rules for values. This package is a python implementation\nof [protoc-gen-validate][pgv-home], which allows for runtime validation of various \nsemantic assertions expressed as annotations on the protobuf schema. The syntax for all available annotations is\nin `validate.proto`. Implemented Python annotations are listed in the [rules comparison][rules-comparison].\n\n### Example\n```python3\nfrom entities_pb2 import Person\nfrom protoc_gen_validate.validator import validate, ValidationFailed, validate_all\n\np = Person(name=\"Foo\")\ntry:\n validate(p)\nexcept ValidationFailed as err:\n print(err) # p.id is not greater than 999\n \ntry:\n validate_all(p)\nexcept ValidationFailed as err:\n print(err) \n # p.id is not greater than 999\n # p.email is not a valid email\n # p.name pattern does not match ^[^[0-9]A-Za-z]+( [^[0-9]A-Za-z]+)*$\n # home is required.\n```\n\n[pgv-home]: https://github.com/envoyproxy/protoc-gen-validate\n[rules-comparison]: https://github.com/envoyproxy/protoc-gen-validate/blob/main/rule_comparison.md\n",
"bugtrack_url": null,
"license": "",
"summary": "PGV for python via just-in-time code generation",
"version": "1.0.4",
"project_urls": {
"Homepage": "https://github.com/bufbuild/protoc-gen-validate"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3e4644ebfd4ec008dd3b0a235df57b11cae3c10b53f581a051573d4f7decb302",
"md5": "04e19ba30a934250edc44a37dee64111",
"sha256": "e38953396924d8948001bea118e92874eff55f93acbb999497fb18209464581f"
},
"downloads": -1,
"filename": "protoc_gen_validate-1.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "04e19ba30a934250edc44a37dee64111",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 18039,
"upload_time": "2024-01-17T16:37:11",
"upload_time_iso_8601": "2024-01-17T16:37:11.387766Z",
"url": "https://files.pythonhosted.org/packages/3e/46/44ebfd4ec008dd3b0a235df57b11cae3c10b53f581a051573d4f7decb302/protoc_gen_validate-1.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3fa523d7cb04f7e714ed854e5497247806d97db20f39c4268df26ed66816b2d6",
"md5": "90277d6127fe16e814c110e1bf1135d5",
"sha256": "5154f763a12d41e656643c5002bca996c2a470eff914ed9d2b2c9f2d7b0f1cc7"
},
"downloads": -1,
"filename": "protoc-gen-validate-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "90277d6127fe16e814c110e1bf1135d5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 18029,
"upload_time": "2024-01-17T16:37:13",
"upload_time_iso_8601": "2024-01-17T16:37:13.060416Z",
"url": "https://files.pythonhosted.org/packages/3f/a5/23d7cb04f7e714ed854e5497247806d97db20f39c4268df26ed66816b2d6/protoc-gen-validate-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-17 16:37:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bufbuild",
"github_project": "protoc-gen-validate",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "flake8",
"specs": [
[
"==",
"3.8.4"
]
]
},
{
"name": "isort",
"specs": [
[
"==",
"5.7.0"
]
]
},
{
"name": "build",
"specs": [
[
"==",
"0.3.0"
]
]
},
{
"name": "twine",
"specs": [
[
"==",
"3.3.0"
]
]
},
{
"name": "wheel",
"specs": [
[
"==",
"0.38.1"
]
]
},
{
"name": "setuptools",
"specs": [
[
"==",
"65.5.1"
]
]
},
{
"name": "protobuf",
"specs": [
[
"==",
"3.20.2"
]
]
},
{
"name": "setuptools_scm",
"specs": [
[
">=",
"6.2"
]
]
}
],
"lcname": "protoc-gen-validate"
}