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

39 questions
5
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,384
  • 2
  • 30
  • 37
3
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
  • 580
  • 1
  • 3
  • 15
2
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
  • 4,217
  • 3
  • 17
  • 30
2
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
  • 23
  • 2
1
vote
1 answer

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
  • 978
  • 1
  • 7
  • 21
1
vote
1 answer

Dropdown menu in Swagger with Flask (restx)

I am building my first API with the flask-restx lib. I use it to generate a Swagger documentation of my API with annotations. I currently have some fields for a post method but they all accept input as strings by default and you have to type their…
Ghostwriter
  • 2,201
  • 2
  • 12
  • 16
1
vote
1 answer

How to return a nested json response in Flask-Restx

I am trying to make an API with Flask-RestX that can show a response like this, { "id": 1, "msg": "How are things", "score": 345, "additional": { "goal": 56, "title": "ASking how" } } when data is like this (In my case, I do not…
realsdx
  • 28
  • 1
  • 6
1
vote
1 answer

How to use data obtained from DB as values in add_argument() when the flask app starts?

I have the following project structure for a flask app using flask-restx . ├── app │   ├── extensions.py │   ├── __init__.py │   └── pv_dimensioning │   ├── controller.py │   ├── __init__.py │   ├── models │   │   ├── dto.py │   …
Junkrat
  • 2,432
  • 2
  • 14
  • 33
1
vote
0 answers

Swagger is not working in server in flask-restx

I've deployed my flask-backend server with Nginx. I can see my swagger documentation locally going 127.0.0.1:5000 also going to my server IP address and port number server_ip:5000. Can I see my API documentation just going my server domain name?…
1
vote
0 answers

Python Flask_restplus flash_restx dynamic marshalling response

Is it possible to dynamicaly modify the marshalled response model (ie : change fields list, add mask, ...) ? ex : from flask_restplus import Resource, fields model = api.model('Model', { 'name': fields.String, 'address': fields.String, …
Nathalie
  • 445
  • 3
  • 14
1
vote
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
  • 83
  • 7
1
vote
1 answer

Flask restx MarshallingError incorrect formatting

Problem context I'm experiencing some unexpected behaviour with MarshallingError, when generating api documentation using flask-restx. I have a custom flask-restx field definition, like below. class EnumField(StringMixin, Raw): def…
Josmoor98
  • 1,418
  • 5
  • 21
1
vote
1 answer

Flask-Restx(/Flask-Restplus) detect reload

my problem is the following: In my Flask-Restx-Application I created a Runner-Thread which runs asynchronously to the main-thread of the Flask-Application. Now when I do changes as usual the Debugger still shows * Detected change in 'XXXXX',…
Cedric
  • 382
  • 1
  • 2
  • 15
0
votes
1 answer

flask restex @expect with nested fields

I am using nested fields to validate an incoming post request using @api.expect like payload1 = api.model('Payload', { 'prop1': fields.Nested({'prop1_inner' : fields.String(required=True)}) }) payload2 = api.model('Payload', { 'prop1':…
user2599052
  • 753
  • 1
  • 8
  • 19
0
votes
1 answer

Add doc decorators on Namespace instantiation flask_restx

I'm trying to add OpenAPI/Swagger docs to a flask_restx Namespace class. The documented way of adding docs it's done by adding the doc decorator over a Resource class: @ns.doc(description="my documentation"). In Namespace class there is a decorators…
1
2 3