https://github.com/nf1s/pydantic-webargs
A library for parsing and validating http requests for Flask web framework using pydantic library
https://github.com/nf1s/pydantic-webargs
decorator flask flask-extension json json-parser parser pydantic web webargs
Last synced: 12 months ago
JSON representation
A library for parsing and validating http requests for Flask web framework using pydantic library
- Host: GitHub
- URL: https://github.com/nf1s/pydantic-webargs
- Owner: nf1s
- License: mit
- Created: 2020-05-27T08:41:43.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T12:41:21.000Z (over 3 years ago)
- Last Synced: 2024-03-15T07:04:09.358Z (about 2 years ago)
- Topics: decorator, flask, flask-extension, json, json-parser, parser, pydantic, web, webargs
- Language: Python
- Homepage: https://ahmednafies.github.io/pydantic-webargs/
- Size: 868 KB
- Stars: 16
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Pyndatic Webargs
[](https://circleci.com/gh/nf1s/pydantic-webargs) [](https://codecov.io/gh/nf1s/pydantic-webargs)  [](https://pepy.tech/project/pydantic-webargs) 
A library for parsing and validating http requests for flask web-framework using pydantic library
Full documentation [here](https://nf1s.github.io/pydantic-webargs/)
## Requirements
python >= 3.7
## How to install
```bash
pip install pydantic-webargs
```
## Dependencies
flask
pydantic
## Example
```python
from flask import Flask
from pydantic import BaseModel
from pydantic_webargs import webargs
app = Flask(__name__)
class QueryModel(BaseModel):
name: str
class BodyModel(BaseModel):
age: int
@app.route("/get-request", methods=["GET"])
@webargs(query=QueryModel)
def example_get_endpoint(**kwargs):
response = kwargs
return response
@app.route("/post-request", methods=["POST"])
@webargs(query=QueryModel, body=BodyModel)
def example_post_endpoint(**kwargs):
print(kwargs)
response = kwargs
return response
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
```