Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/shangsky/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. Flask Sugar是一个基于flask,pydantic,类型注解的API框架, 可以检查参数并自动生成API文档
https://github.com/shangsky/flask-sugar

flask openapi python swagger

Last synced: about 1 month ago
JSON representation

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. Flask Sugar是一个基于flask,pydantic,类型注解的API框架, 可以检查参数并自动生成API文档

Awesome Lists containing this project

README

        

# Flask Sugar

- [简体中文](README_zh.md)

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: or

Source Code:

## Requirements

- Python 3.6+
- Flask 2.0+

## Installation

```shell
$ pip install flask-sugar
```

## Example

```python
# 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/")
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)
```

```shell
$ 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:

![](https://github.com/ShangSky/flask-sugar/raw/main/docs/img/swagger-ui.png)

visit the API documentation with Redoc at http://localhost:5000/redoc:

![](https://github.com/ShangSky/flask-sugar/blob/main/docs/img/redoc.png)

## License

This project is licensed under the terms of the MIT license.