A small decorator for post data view validation
Project description
Dillinger
faust-pydantic-validate is a small decorator to validate post data.
Installation
pip install faust-pydantic-validate
Usage
from pydantic import BaseModel
from faust.types.web import Request, Response
from faust.web import View
from faust_pydantic_validate.wrappers import takes_pydantic
app = faust.App(
'foo',
broker='kafka://localhost:9092',
)
class FooBar(BaseModel):
foobar: int
@app.page('/build/')
class Builder(View):
@takes_pydantic(FooBar, include_schema=True)
async def post(self, request: Request, validated_object: BaseModel, **kwargs: Any) -> Response:
return self.json(value=validated_object.dict())
Request data
{
"foobar": 1
}
Response data
{
"foobar": 1
}
Request data
{
"foobar": "foo"
}
Response data (include_schema=True)
"errors": [
{
"loc": [
"foobar"
],
"msg": "value is not a valid integer",
"type": "type_error.integer"
}
],
"schema": {
"title": "FooBar",
"type": "object",
"properties": {
"foobar": {
"title": "Foobar",
"type": "integer"
}
},
"required": [
"foobar"
]
}
}
Response data (include_schema=False)
{
"errors": [
{
"loc": [
"foobar"
],
"msg": "value is not a valid integer",
"type": "type_error.integer"
}
]
}
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
Built Distributions
Close
Hashes for faust_pydantic_validate-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b65342ac31533835cb2870b280e1e08d000814035b64d9d676a01e7569024ff9 |
|
MD5 | fcd88aa016835a953ecae768e53ea846 |
|
BLAKE2b-256 | 6d14fb726cbb1fe5560896f67cb17c14ffeb097cd6a99c880fee85727ddaf3ae |
Close
Hashes for faust_pydantic_validate-0.0.2-py3.9.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbd1e5135c949b4755720b8f614ac172b683af9d14a09fc1736f66e86596b3ad |
|
MD5 | d4b885946055849e1c261d0e83b685f5 |
|
BLAKE2b-256 | 90d53d992072bd42bdf341e6f34d30a1d6d584edb8394e78f2013fd817a1b1e7 |
Close
Hashes for faust_pydantic_validate-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3563b40ea74fadc1e00b1c8caa2c7af370547bd06d277ac2007c1a5fafa3d960 |
|
MD5 | afdc4aff75cd261e5c34eac62e684956 |
|
BLAKE2b-256 | 3f2c9f48755808c4a78e903809e23b1f0c8592b72ce0feb9a3e86c98a8c390d6 |