Flask Sugar is a web framework for building APIs with Flask, Pydantic and Python 3.6+ type hints.

Overview

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

A Simple Example

Resp: """index page""" return {"code": 0, "msg": "success", "data": {}} ">
# save this as main.py
from typing import Any

from flask_sugar import Sugar
from typing_extensions import TypedDict

app = Sugar(__name__)


class Resp(TypedDict):
    code: int
    msg: str
    data: Any


@app.get("/")
def index() -> Resp:
    """index page"""
    return {"code": 0, "msg": "success", "data": {}}
$ export FLASK_APP=main:app
$ 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.

Issues
  • [Bug Report]When I use extension flask-admin , error happended.

    [Bug Report]When I use extension flask-admin , error happended.

    flask 2.0.2 flask-admin 1.6.0 flask-sugar 0.0.14

    127.0.0.1 - - [08/Feb/2022 10:46:51] "GET /apis/openapi.json HTTP/1.1" 500 - Traceback (most recent call last): File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask/app.py", line 2091, in call return self.wsgi_app(environ, start_response) File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask/app.py", line 2076, in wsgi_app response = self.handle_exception(e) File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask/app.py", line 2073, in wsgi_app response = self.full_dispatch_request() File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask/app.py", line 1518, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask/app.py", line 1516, in full_dispatch_request rv = self.dispatch_request() File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask/app.py", line 1502, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask_sugar/view.py", line 312, in call response = self.view_func(**cleaned_data) File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask_sugar/openapi.py", line 77, in openapi_json_view paths, components = collect_paths_components() File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask_sugar/openapi.py", line 198, in collect_paths_components flat_models, model_name_map=model_name_map, ref_prefix=REF_PREFIX File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask_sugar/openapi.py", line 185, in schema model_name = model_name_map[model] KeyError: <class 'pydantic.main.flask_admin__model__base__export__ParamModel'>

    opened by shijl0925 8
  • can you support operation mode config for the routes?

    can you support operation mode config for the routes?

    I found all routes have operation in the swagger and redoc api docs. can you support operation mode config for the routes.

    1. 'default': includes all routes in this instance.

    2. 'strict': only includes routes which I wanted.

    opened by shijl0925 3
  • [Bug Report] Duplicate swagger/redoc api docs when I use flask_sugar's Blueprint

    [Bug Report] Duplicate swagger/redoc api docs when I use flask_sugar's Blueprint

    code:

    
    from flask_sugar import Blueprint
    auth_bp = Blueprint('auth', __name__, url_prefix='/auth')
    
    @auth_bp.post('/obtain/token', tags=['Auth'])
    def obtain_token(payload: ObtainToken):
        ...
    
    

    20220209102311

    20220209102349

    opened by shijl0925 2
  • Using BaseModel in the GET parameters, is it possible?

    Using BaseModel in the GET parameters, is it possible?

    I want GET query parameters have some validation. can you support it?

    example code:

    ` import datetime from typing import List

    from pydantic import Field, BaseModel from flask_sugar import Query

    class SettingQuery(BaseModel): page: Optional[int] = Field(..., ge=1, description='page number') limit: Optional[int] = Field(..., ge=1, le=25, description='limit number') query: str = None

    @apis_bp.get("/settings") def settings(query: SettingQuery = Query(...)): return {"query": query.dict()} `

    opened by shijl0925 2
  • [Bug Report]When I use extension flask-debugtoolbar , error happended.

    [Bug Report]When I use extension flask-debugtoolbar , error happended.

    AssertionError: View function mapping is overwriting an existing endpoint function: debugtoolbar.sql_select

    Traceback (most recent call last) File "/Users/shijl0925/Pycharm/flask-example/backend/app/main.py", line 170, in app = create_app() File "/Users/shijl0925/Pycharm/flask-example/backend/app/main.py", line 144, in create_app register_extensions(app_) File "/Users/shijl0925/Pycharm/flask-example/backend/app/main.py", line 88, in register_extensions extension.init_app(app) File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask_debugtoolbar/init.py", line 84, in init_app app.register_blueprint(module, url_prefix='/_debug_toolbar/views') File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask/scaffold.py", line 57, in wrapper_func return f(self, *args, **kwargs) File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask/app.py", line 1028, in register_blueprint blueprint.register(self, options) File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask/blueprints.py", line 370, in register deferred(state) File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask/blueprints.py", line 426, in **options, File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask/blueprints.py", line 108, in add_url_rule **options, File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask_sugar/app.py", line 143, in add_url_rule super().add_url_rule(rule, endpoint, view, provide_automatic_options, **options) File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask/scaffold.py", line 57, in wrapper_func return f(self, *args, **kwargs) File "/Users/shijl0925/Pycharm/flask-example/backend/venv/lib/python3.7/site-packages/flask/app.py", line 1091, in add_url_rule "View function mapping is overwriting an existing" AssertionError: View function mapping is overwriting an existing endpoint function: debugtoolbar.sql_select

    opened by shijl0925 1
  • support swagger redoc security

    support swagger redoc security

    非常喜欢你的库,但是我发现api文档的各个方法并不能支持独立配置Security schemes, 我提交了如下代码,帮忙review。我本地验证是ok的。 谢谢。 功能:支持 路由方法的 swagger redoc api文档的 安全配置 support Security schemes for particular method.

    opened by shijl0925 1
Chisel is a light-weight Python WSGI application framework built for creating well-documented, schema-validated JSON web APIs

chisel Chisel is a light-weight Python WSGI application framework built for creating well-documented, schema-validated JSON web APIs. Here are its fea

Craig Hobbs 2 Dec 2, 2021
Web framework based on type hint。

Hint API 中文 | English 基于 Type hint 的 Web 框架 hintapi 文档 hintapi 实现了 WSGI 接口,并使用 Radix Tree 进行路由查找。是最快的 Python web 框架之一。一切特性都服务于快速开发高性能的 Web 服务。 大量正确的类型

Aber 20 May 4, 2022
Sierra is a lightweight Python framework for building and integrating web applications

A lightweight Python framework for building and Integrating Web Applications. Sierra is a Python3 library for building and integrating web applications with HTML and CSS using simple enough syntax. You can develop your web applications with Python, taking advantage of its functionalities and integrating them to the fullest.

null 81 Jun 12, 2022
The Python micro framework for building web applications.

Flask Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to co

The Pallets Projects 60.1k Aug 8, 2022
Pyrin is an application framework built on top of Flask micro-framework to make life easier for developers who want to develop an enterprise application using Flask

Pyrin A rich, fast, performant and easy to use application framework to build apps using Flask on top of it. Pyrin is an application framework built o

Mohamad Nobakht 10 Jan 25, 2022
Web APIs for Django. 🎸

Django REST framework Awesome web-browsable Web APIs. Full documentation for the project is available at https://www.django-rest-framework.org/. Fundi

Encode 23.9k Aug 15, 2022
NO LONGER MAINTAINED - A Flask extension for creating simple ReSTful JSON APIs from SQLAlchemy models.

NO LONGER MAINTAINED This repository is no longer maintained due to lack of time. You might check out the fork https://github.com/mrevutskyi/flask-res

null 1k Aug 2, 2022
NO LONGER MAINTAINED - A Flask extension for creating simple ReSTful JSON APIs from SQLAlchemy models.

NO LONGER MAINTAINED This repository is no longer maintained due to lack of time. You might check out the fork https://github.com/mrevutskyi/flask-res

null 1k Jan 15, 2021
Goblet is an easy-to-use framework that enables developers to quickly spin up fully featured REST APIs with python on GCP

GOBLET Goblet is a framework for writing serverless rest apis in python in google cloud. It allows you to quickly create and deploy python apis backed

Austen 63 Aug 9, 2022
An abstract and extensible framework in python for building client SDKs and CLI tools for a RESTful API.

django-rest-client An abstract and extensible framework in python for building client SDKs and CLI tools for a RESTful API. Suitable for APIs made wit

Certego 3 Aug 4, 2022
A high-level framework for building GitHub applications in Python.

A high-level framework for building GitHub applications in Python. Core Features Async Proper ratelimit handling Handles interactions for you (

Vish M 3 Apr 12, 2022
APIFlask is a lightweight Python web API framework based on Flask and marshmallow-code projects

APIFlask APIFlask is a lightweight Python web API framework based on Flask and marshmallow-code projects. It's easy to use, highly customizable, ORM/O

Grey Li 631 Aug 4, 2022
web.py is a web framework for python that is as simple as it is powerful.

web.py is a web framework for Python that is as simple as it is powerful. Visit http://webpy.org/ for more information. The latest stable release 0.62

null 5.7k Aug 7, 2022
A public API written in Python using the Flask web framework to determine the direction of a road sign using AI

python-public-API This repository is a public API for solving the problem of the final of the AIIJC competition. The task is to create an AI for the c

Lev 1 Nov 8, 2021
Flask-Potion is a RESTful API framework for Flask and SQLAlchemy, Peewee or MongoEngine

Flask-Potion Description Flask-Potion is a powerful Flask extension for building RESTful JSON APIs. Potion features include validation, model resource

DTU Biosustain 489 Jul 25, 2022
Flask-Potion is a RESTful API framework for Flask and SQLAlchemy, Peewee or MongoEngine

Flask-Potion Description Flask-Potion is a powerful Flask extension for building RESTful JSON APIs. Potion features include validation, model resource

DTU Biosustain 484 Feb 3, 2021
Asita is a web application framework for python based on express-js framework.

Asita is a web application framework for python. It is designed to be easy to use and be more easy for javascript users to use python frameworks because it is based on express-js framework.

Mattéo 4 Nov 16, 2021
A Python package to easily create APIs in Python.

API_Easy An Python Package for easily create APIs in Python pip install easy-api-builder Requiremnets: <= python 3.6 Required modules --> Flask Docume

Envyre-Coding 2 Jan 4, 2022
Containers And REST APIs Workshop

Containers & REST APIs Workshop Containers vs Virtual Machines Ferramentas Podman: https://podman.io/ Docker: https://www.docker.com/ IBM CLI: https:/

Vanderlei Munhoz 8 Dec 16, 2021