Using Swagger with Flask

40,986

Solution 1

Flask is now supported from the Swagger Editor: http://editor.swagger.io/#/

Solution 2

There is Flask-RESTPlus based on Flask-Restful until now. It provides some decorators to document your API and generate a Swagger specification, a Postman collection...

Next version will be able to generate the API from Swagger specifications.

Solution 3

You can also use connexion

"Connexion is a framework on top of Flask to automagically handle your REST API requests based on Swagger 2.0 Specification files in YAML."

Solution 4

You can use flask-restful-swagger.

Solution 5

Flasgger is an extension to make automatic UI for Flask routes http://github.com/rochacbruno/flasgger

Share:
40,986
Adam Matan
Author by

Adam Matan

Team leader, developer, and public speaker. I build end-to-end apps using modern cloud infrastructure, especially serverless tools. My current position is R&D Manager at Corvid by Wix.com, a serverless platform for rapid web app generation. My CV and contact details are available on my Github README.

Updated on April 06, 2020

Comments

  • Adam Matan
    Adam Matan about 4 years

    Is there a way to generate a RESTful API in Flask using Swagger?

  • nycynik
    nycynik about 8 years
    This is a great choice, it works just like restify, but includes swagger, and it includes the swagger UI.
  • Ron Kalian
    Ron Kalian over 5 years
    Connexion is based on OpenAPI 2.0 Specification. This is disappointing as OpenAPI has since moved on to 3.0!
  • Ron Kalian
    Ron Kalian over 5 years
    Connexion 2 was recently released - it claims to implement OpenAPI 3.0. I found it adheres to the spec more closely if connexion.App() is defined with options={'uri_parsing_class': OpenAPIURIParser } param
  • Bob Denny
    Bob Denny over 5 years
    I only wish that @api.doc(...) and other Swagger doc decorators in Flask-RESTPlus 0.12 were documented better. I am spending HUGE time shooting in the dark to get the doc like I want it.
  • noirbizarre
    noirbizarre over 5 years
    There is an entire documentation page only for the documentation decorators: flask-restplus.readthedocs.io/en/stable/swagger.html If something is unclear or missing, please submit pull-requests (or ask)
  • Craig Brett
    Craig Brett about 5 years
    Thing is, to PR with the bits that are unclear and or missing, you need to know what the solution is. I spent ages earlier trying to make a field a password type input. Random things like that. Oh and trying to have an API spread across more than 1 file. Don't get me wrong this is my answer of choice for this problem, but it's sometimes harder than it should be to achieve things
  • MikeL
    MikeL about 4 years
    IMPORTANT to note that the Flask-RESTPlus project should be considered unmaintained and been forked to another side project.
  • Ben Mares
    Ben Mares almost 4 years
    This may not be a correct answer (technically it uses Starlette instead of Flask), but it is IMHO by far the best. I tried all the other options and was dismayed that they fail to take advantage of modern Python. In contrast, the serialization, typing and routing with FastAPI are beautifully implemented, and being actively improved. Starlette is very similar to Flask, so there is barely any learning curve.