Flask Sugar is a web framework for building APIs with Flask, Pydantic and Python 3.6+ type hints.
Project description
Flask Sugar
Flask Sugar is a web framework for building APIs with Flask, Pydantic and Python 3.6+ type hints.
check parameters and generate API documents automatically
Documentation: https://shangsky.github.io/flask-sugar
Source Code: https://github.com/shangsky/flask-sugar
Requirements
- Python 3.6+
- Flask 2.0+
Installation
$ pip install flask-sugar
Example
# save this as app.py
from flask_sugar import Sugar, Header
from pydantic import BaseModel
app = Sugar(__name__)
class Item(BaseModel):
name: str
size: int
class Resp(BaseModel):
a: int
b: str
c: str
item: Item
@app.post("/item/<a>")
def demo(
a: int, # path param
item: Item, # json body param
b: str = "default_query_param_b", # query param
c: str = Header("default_header_param_b"), # request header param
) -> Resp:
"""demo page"""
return Resp(a=a, b=b, c=c, item=item)
$ flask run --reload
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Now visit the API documentation with Swagger UI at http://localhost:5000/doc:
visit the API documentation with Redoc at http://localhost:5000/redoc:
License
This project is licensed under the terms of the MIT license.
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
flask-sugar-0.0.11.tar.gz
(11.9 kB
view hashes)
Built Distribution
Close
Hashes for flask_sugar-0.0.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb50f142f4604d46f177fc7445171427e9e4dd615fc11f8ca5817a9414846211 |
|
MD5 | 08f1ee78ce380c1a7f883fd1f31df2a8 |
|
BLAKE2b-256 | 1380a165604ae42865dc7179452da80a4d7d48a007e44befa611bbd19709fbfb |