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
1
vote
2 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
  • 625
  • 6
  • 19
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,721
  • 10
  • 27
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
  • 408
  • 1
  • 4
  • 18
0
votes
0 answers

Attempt to create swagger documentation for a `Flask` rest endpoint causes PDF to be treated as JSON via `flask_restx`

I have the following code which converts a HTML file upload to a PDF using a Python Flask web server REST endpoint. The file is uploaded as multi-part form data. It works great, but when I tried to add Swagger to the REST endpoint using flask_restx…
Superdooperhero
  • 7,584
  • 19
  • 83
  • 138
0
votes
0 answers

Flask and Flask Restx application GET returns the API description instead of the function defined in a class

Currently creating a flask and flask-restx python project where im using the post and get functions in a class which inherits the "Resource" from flask-restx. I first started with the "post" function which worked perfectly, but when implementing a…
0
votes
0 answers

Logging from within Flask-RestX endpoints

I'm trying to create logs from my Flask-RestX endpoints so I can see when they're being hit. Even with the most basic of logging configurations, I am unable to get the logs to write anywhere. I've read some conflicting articles about how Flask vs…
0
votes
1 answer

Conditional hiding/showing endpoint's swagger doc with Flask-RESTX

I am trying to conditionally hide/show an endpoint swagger doc with Flask-RESTx, I am aware of using @api.doc(False) to disable (as shown here Hide endpoints in UI of Flask restful Swagger) however, it doesn't work with @api.route("/register",…
barha
  • 709
  • 1
  • 7
  • 22
0
votes
0 answers

Flask unit test uses/accesses development databse even after creating a temporary database to test

I have created a flask App and this is the app.py file from flask_migrate import Migrate from dotenv import load_dotenv import os from src.app import create_app, db load_dotenv() app = create_app() Migrate(app, db) if __name__ == '__main__': …
Glen Veigas
  • 186
  • 11
0
votes
0 answers

Flask-Restx fails to render Swagger when 'required' parameter is used in 'model'

from flask_restx import Resource, Namespace, fields api_users = Namespace("", description="") login_model = api_users.model( "LoginModel", { "email": fields.String(required=True, min_length=4, max_length=64), …
0
votes
0 answers

How to make my swagger curl match my apache config?

I'm running flask restx behind gunicorn and apache. My team only gets one server for all our tools so it's kind of necessary. But in order to work w/ port 443 and https, I'm having to proxy my requests through apache and gunicorn. Apache…
0
votes
0 answers

How do I add 'Bearer' to the Authorization header for my Flask Blueprint API using Swagger?

add bearer token to api header in Swagger flask blueprint comment_namespace = Namespace('comment', "create and update comments",authorizations={ 'Bearer': { 'type': 'apiKey', 'in': 'header', 'name': 'Authorization' …
0
votes
0 answers

Flaskrestx swagger page empty w apache proxy

I'm using Flaskrestx and Apache to try and display a swagger page. On my local machine, it comes up just fine at http://localhost:5000/. But on my server, I just get an empty page. Apache config: ServerName myserver.com ##…
0
votes
1 answer

Can't update a record using flask-restx sqlalchemy mariadb v10.5.20 "(mariadb.NotSupportedError) Data type 'tuple'"

github repository This is a simple REST API, have 2 classes Client, Product. Relationship: A client can have many products, Client 1---* Product. I can list, create, search by id, with the 2 models, Client and Product. But now working in the…
christianbueno.1
  • 516
  • 1
  • 8
  • 12
0
votes
0 answers

How do I use a JWT header that has underscores with Werkzeug 2.3 and newer?

I have to use a JWT header (key) that is all caps and has underscores, but in a recent version, Werkzeug 2.3.x just discards headers with underscores. I have a decorator that helps parse request headers and due to this change, I cannot upgrade…
0
votes
1 answer

Validate Custom Field in Flask-Restx using @api.expect()

I want to make a custom field when making an API model and validate that it is either a string or boolean or a list I have tried class CustomField(fields.Raw): __schema_type__ = ["String", "Boolean", "List"] __schema_example__ = "string or…