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
38
votes
4 answers

ImportError: cannot import name 'parse_rule' from 'werkzeug.routing'

I got the following message after running my Flask project on another system. The application ran all the time without problems: Error: While importing 'app', an ImportError was raised: Traceback (most recent call last): File…
ChsharpNewbie
  • 1,040
  • 3
  • 9
  • 21
11
votes
5 answers

TypeError: __init__() got an unexpected keyword argument 'unbound_message'

I got the above error when I try to import fields from flask_restx. from flask_restx import fields What is the problem. It works on my local machine but not on remote machine. Full error trace: File…
Mark
  • 644
  • 1
  • 4
  • 11
10
votes
2 answers

How to use Marshmallow Schema in Flask-restx Swagger UI Automatically

I'm trying to create a restful web services with flask-restx and marshmallow. I'm using marshmallow for both request and response validations. Since flask-restx api docs does not support marshmallow schemas in swagger ui, i want to add it using doc…
Angus G.
  • 79
  • 1
  • 6
9
votes
0 answers

How to model OneOf in Flask Restx?

I have the following schema doc { "$schema": "http://json-schema.org/draft-07/schema#", "title": "foo", "definitions": { "stuff": { "type": "object", "properties": { "id": { …
dranobob
  • 796
  • 1
  • 5
  • 19
6
votes
2 answers

Adding auth decorators to flask restx

I have a Flask application using flask-restx and flask-login. I would like all routes by default to require login, and explicitly define public routes that require no authentication. I have started using decorators following the example given in…
mikelong
  • 3,694
  • 2
  • 35
  • 40
5
votes
0 answers

Is there a way to marshal different response codes in flask_restx?

With: @api.marshal_with(response_model, code=200) We can marshal a response with a predefined response model response_model and a status code. My question is let's say we run a validation on the request and we want to throw a 400 error. Is it…
Franco Piccolo
  • 6,845
  • 8
  • 34
  • 52
4
votes
2 answers

How to specify schema for nested json in flask_restx?

Im using flask_restx for swagger API's. The versions are as follows: python - 3.8.0 flask - 2.0.2 flask_restx - 0.5.1 The following is the nested json I need to specify the schema for: dr_status_fields = app_api.model('DR Status',{ …
rakesh kotian
  • 232
  • 1
  • 5
  • 30
3
votes
0 answers

flask_restx APP with Nginx + Gunicorn in Docker doesn't respond to HTTP-Requests

My flask_restx application is running in a docker container, with nginx as reverse proxy and Gunicorn workers. When I send a HTTP-Request to my application, the expected result is a response after the application does its job, which takes about 3-5…
3
votes
1 answer

Adding 'Value Example' to swagger, using flask-restx

how can i add 'value example' (like on picture 3) to swagger documentation (picture 4 is that where i want to put 'value example' in) without using decorator marshall_with/marshall_list_with? Cuz the function got two responses depending on two…
Chep
  • 41
  • 2
3
votes
1 answer

How to set username and password for basic auth in flask restx swagger?

Im trying to add basic Authorization to my flask rest-x application. By referring to https://github.com/python-restx/flask-restx/issues/271 I have made code changes. But here there is no clarity on how to set and a username and password. As well in…
3
votes
1 answer

difference between Flask-RESTful and Flask-RESTx

What is the difference between Flask-RESTful and Flask-RESTx? Is it more advantageous to use Flask-RESTx instead of Flask-RESTful?
can_92
  • 43
  • 3
3
votes
2 answers

Flask-Restx Swagger Doc issue

I am getting AttributeError: module 'flask_restx.api' has no attribute 'doc' when it try add additional for API when using flask restx. How this error can be fixed. api.py from flask import Flask from flask_restx import Api, Resource from hello…
Arul
  • 143
  • 3
  • 12
3
votes
1 answer

Flask-Restx & Swagger Authorizations Sending Incorrect Token in Header

I have a Flask REST API that is using Flask-Restx, and JWT token authentication and is working making calls out of postman. However, when I am trying to use swagger, the token being sent is not the one I am inputting through the interface. My code…
ghawes
  • 193
  • 1
  • 11
3
votes
1 answer

Flask restx model nested wildcard dict

I was wondering if I'm only one struggling with such problem. Lets take dict for example: data = {'totalSize': 3000, 'freq': 2400, 'distribution': {'ram1': {'size': 200, 'status': 'OK'}, 'ram2': {'size': 100,…
Devourer
  • 33
  • 1
  • 3
2
votes
1 answer

Flask restx multipart/form request with file and body with swagger

I am trying to implement, using flask-restx, an endpoint which will take both formData (a list of files to be more precise) and a body as json. My code looks as follow: Multiple files param in some module: def authorization_param(ns: Namespace,…
1
2 3 4 5 6 7 8