Questions tagged [flask-restx]

Flask-RESTX is an extension for Flask that adds support for quickly building REST APIs in Python. Flask-RESTX is a community-driven fork of Flask-RESTPlus, hence users can also make use of [flask-restplus] tag in addition to [flask-restx] to search for relevant issues and questions.

Flask-RESTX is an extension for Flask that adds support for quickly building REST APIs.

Flask-RESTX encourages best practices with minimal setup. If you are familiar with Flask, Flask-RESTX should be easy to pick up.

It provides a coherent collection of decorators and tools to describe your API and expose its documentation properly using Swagger.

Flask-RESTX is a community driven fork of Flask-RESTPlus


A Minimal API

A minimal Flask-RESTX API looks like this:

from flask import Flask
from flask_restx import Resource, Api

app = Flask(__name__)
api = Api(app)

@api.route('/hello')
class HelloWorld(Resource):
    def get(self):
        return {'hello': 'world'}

if __name__ == '__main__':
    app.run(debug=True)

Compatibility

Flask-RESTX requires Python 2.7 or 3.4+.

Documentation

The documentation is hosted on Read the Docs

108 questions
2
votes
1 answer

Swagger documentation for flask api is generated on 2 different urls: one for routes using flask_restx and another - for others using swag_from

Please help! I am new to Swagger and to writing flask APIs. We are still researching the best practices, so I needed to create some routes using Blueprint and swag_from: from flasgger import swag_from While i have one other route that is using…
JustLearning
  • 180
  • 2
  • 12
2
votes
2 answers

Flask-restx request parser returns 400 Bad Request

I'm using flask-restx in my flask application but each time I use the swagger ui to make a request it returns this 400: http://127.0.0.1:5000/api/user/register/?password=test&email=test&username=test { "message": "Did not attempt to load JSON…
Peter
  • 41
  • 4
2
votes
0 answers

python flask-restx - how to avoid creating different models for post and get

I am trying to rest server with python flask-restx module. My table has two columns id and value. id column is a auto-increment primary key. so for post I don't need to pass id but for get I need show it in the response. Is there any way I can…
Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137
2
votes
1 answer

flask_restx - api.expect from two sources for swagger

Hei there! I have a flask restx api and I have an endpoint that essentially needs to do the following filters = api.model('filters', { x = fields.Raw('x') } parser = reqparse.RequestParser() parser.add_argument('b', type=int,…
isebarn
  • 3,812
  • 5
  • 22
  • 38
2
votes
2 answers

flask-restplus /flask-restx automatically add 401 response to Swagger docs if authentication is on

As the title mentions, I would like to have a @api.response(401, 'Unauthenticated') response added to the documentation of all APIs which require authentication. flask-resplus/restx displays a lock icon, so the user should expect a 401 if not…
mibm
  • 1,328
  • 2
  • 13
  • 23
2
votes
1 answer

How can I move my static folder to an url with a prefix with flask-restx

I am trying to deploy an app flask using flask-restx package and I am stuck on how to display properly the documentation on the prod server. It works well locally without any prefix, but on the server, the files url need to be prefixed by my-prefix…
kiki
  • 563
  • 4
  • 17
2
votes
1 answer

Having Trouble Making a RESTful API with Flask-RestX: "No operations defined in spec!" and "404"s

In summary, I have been following the flask restx tutorials to make an api, however none of my endpoints appear on the swagger page ("No operations defined in spec!") and I just get 404 whenever I call them I created my api mainly following this…
Alex
  • 161
  • 1
  • 7
1
vote
3 answers

How to use url_for with flask_restx?

I can use url_for in a flask 2.0.1 template like along with @app.route('/import/images') def testimport(): return "ok" but I…
x y
  • 911
  • 9
  • 27
1
vote
1 answer

Flask restx response marshalling

I know that response marshalling looks something like this: from flask_restx import fields some_object = { 'id': fields.Integer(reqired=True), 'name': fields.String(required=True) } @api.route('', methods=['POST']) class…
cassham
  • 21
  • 2
1
vote
1 answer

Python, Mqtt : can publish but can't receive message on docker

I'm running two dockers : one for the mqtt server using mosquitto the other using flask_mqtt the flask container is receiving the CONNACK and is sending the subscribe to the broker but never get any SUBACK however it manages to publish hello word to…
Tx Mat
  • 13
  • 5
1
vote
0 answers

How define host flag of swagger with flask-restx?

I am using the Flask-RestX to generate an automatic swagger 2.0 documentation. But I can not find how I could define the flag "host" by RestX. I use this code to generate swagger.json automatic with RestX: # app.py from flask import Flask from flask…
natielle
  • 380
  • 3
  • 14
1
vote
0 answers

Flask RestX with nested collections and items

I'm looking for advice on a design pattern for creating a REST API using Flask (with flask restx) handling multiple collections ("hub") which each have items ("nodes"). Example: HubA will have N nodes it manages. HubB will have M nodes it…
PBear
  • 11
  • 2
1
vote
1 answer

Error displaying Swagger UI of flask-restx in Deployment using uwsgi and nginx

I have implemented a flask rest server with swagger-ui using flask-restx. I could get the swagger-ui working when running the server using command, without nginx flask run --host=0.0.0.0 or uwsgi --ini app.ini My app.ini: [uwsgi] module =…
Simk0024
  • 61
  • 7
1
vote
1 answer

How to reuse the nested Resource methods in the encompassing Resource methods?

I have a resource called Profile which nests a list of Port resources like so: { "profile": "abcd" "ports": [ { "port": "5687" "state": "state" "protocol": "protocol" …
nitin_cherian
  • 6,405
  • 21
  • 76
  • 127
1
vote
2 answers

How to add method description in Swagger UI in PyCharm with Flask-RESTX

I am using Swagger as my API tooling framework and I just found this page: https://petstore.swagger.io/ and saw how each method has a description. For example: POST: pet/ is described by add a new Pet to the store. I thought adding this kind of…
VG_PyGirl
  • 11
  • 2