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 or https://flask-sugar.vercel.app/
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
Built Distribution
File details
Details for the file flask-sugar-0.0.20.tar.gz
.
File metadata
- Download URL: flask-sugar-0.0.20.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.6.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75761b4ad0fe32069c7bbf480010d88de39e0e6cf69d8c387b15ebf927191d47 |
|
MD5 | d1303ceeb7a9609fbc612648fc86e51c |
|
BLAKE2b-256 | 05d4cbf901624040281aa595c451f9c0aa1ea2b5aeb046a1175864cb3668e10d |
File details
Details for the file flask_sugar-0.0.20-py3-none-any.whl
.
File metadata
- Download URL: flask_sugar-0.0.20-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.6.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e9921c5e009c1edfe27d8e2330e49a2a107aff36655d826e368f74f796e1bc1 |
|
MD5 | 69e66c264ef1ef591f0fbf9a950c575b |
|
BLAKE2b-256 | 393547cdd0521b85cc1a9eb643a19a11692d8e1cd3dd233210d6f21795b6be41 |