Giter VIP home page Giter VIP logo

limmyforget / flask-sugar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shangsky/flask-sugar

0.0 0.0 0.0 1.77 MB

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,pyddantic,类型注解的API框架, 可以检查参数并自动生成API文档

License: MIT License

Python 100.00%

flask-sugar's Introduction

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.

flask-sugar's People

Contributors

shangsky avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.