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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | dafe616cef0d70a23a9ed2fd0f1efad80490dfa062ea0463503981d92742484e |
|
MD5 | 37e302ef50415842a79e7c7c3fc86d40 |
|
BLAKE2b-256 | d77d1ea3235132780e3aa4a46d83546554f513db225c837c581b7077da691d05 |
Close
Hashes for faust_pydantic_validate-0.0.1-py3.8.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 569877656397ffa3824e8726209d8c38b4209d7a104ec67c3282c99f2e671a40 |
|
MD5 | 006f43c3f50971590d73917bd8c12e7e |
|
BLAKE2b-256 | b1e49b370861de11c768b2a0f46b9248c7a952eebc8e097a6cf7a93e5fbbf1f1 |
Close
Hashes for faust_pydantic_validate-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0683d261a50c30afed48ee636a60afbae845c2b8bef6c7108250aedd03a15eeb |
|
MD5 | c865ac3c2227fb7c6ad00e0c0fd7ce00 |
|
BLAKE2b-256 | cb0d649fd0a6868d673d0e6fecc48bf8eb519b6ec264ab1978031b5964e0760e |