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
0
votes
2 answers

How to use flask app context when using decorators

I'd like to use token authorization from Flask-Security-Too for this "Article" endpoint. However, the decorator function @auth_token_required("token") needs the context of the app. The app is initialized in a different file. I've added…
DeVolt
  • 321
  • 1
  • 3
  • 15
0
votes
1 answer

Convert json field in body to enum with flask-restx

I have the following api definition for flask-restx (though should also work with flask-restplus). Is there someway to convert the enum-field in the request body the the Enum MyEnum without too much overhead or using DAOs? class MyEnum(Enum): …
Teharez
  • 501
  • 8
  • 25
0
votes
1 answer

flask_restx fields.Raw does not allow None

I just switched from flaks_restplus to flask_restx. I start getting the marshal error. jsonschema.exceptions.ValidationError: None is not of type 'object' I defined this field in my modal, and the dict I passed in. "my_field": fields.Raw {...…
etlds
  • 5,810
  • 2
  • 23
  • 30
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
  • 1,056
  • 3
  • 12
  • 27
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…
Alin Climente
  • 117
  • 1
  • 2
  • 14
0
votes
1 answer

HTTP HEAD for custom header vs partial object fetching

I wish to perform a conditional GET request for a document depending on the value for a particular attribute of that document. I came across two ways that would help me do that. Include this attribute as a custom header for the GET method and use…
Radha Saraf
  • 125
  • 1
  • 12
0
votes
2 answers

Python REST-API with Flask-RestX and JavaScript REST-Client served together

I run this example: https://flask-restx.readthedocs.io/en/latest/example.html (A Python REST-API with Flask-RESTX) Code snippet app = Flask(__name__) api = Api(app, ...) ns = api.namespace('todos',…
0
votes
2 answers

Flask-Restx Api.model(strict=True) allowing unspecified params

I have a simple Users resource with a put method to update all user information except user password. According to Flask-Restx docs when a model has set the strict and validation params to true, a validation error will be thrown if an unspecified…
CLPatterson
  • 113
  • 1
  • 14
0
votes
1 answer

Using RequestParser from Flask to validate that float arguments fall within range

I am creating an API using Flask Restplus on Python that takes in a dictionary of location information ({lat: 10, lon:80}, for example), does some mathematical modelling, and outputs a result. I am currently using the RequestParser object to parse…
0
votes
1 answer

Best practice for scaling SQL queries on joins?

I'm writing a REST api that works with SQL and am constantly finding myself in similar situations to this one, where I need to return lists of objects with nested lists inside each object by querying over table joins. Let's say I have a many-to-many…
Sean
  • 55
  • 4
0
votes
1 answer

Flask-RESTX - Arabic text in response body

I'm running a rest api with swagger, flask-restx However, my problem is that in the swagger UI (http://127.0.0.1:5000/ ?) when testing out the endpoint, arabic text in the response body is returned as excaped characters…
isebarn
  • 3,812
  • 5
  • 22
  • 38
0
votes
1 answer

Cannot import var from top package

This is my project structure: myProject/ | |-- src/ | |-- services/ | | |-- __init__.py | | |-- users.py | | | |-- main.py | |-- ... ... In main I have the mongo var that I need to use in users.py # src/main.py from flask import…
Braven
  • 484
  • 1
  • 6
  • 27
0
votes
1 answer

POST method not being invoked from the URL in API Gateway

I have a basic flask-restx app (main.py) as follows: ns = Namespace( "greetings", description="Get Greetings." ) parser = reqparse.RequestParser() parser.add_argument("name", type=str, help="name") @ns.route('/restx/hello/') class…
0
votes
0 answers

Python Flask API - smtplib throws an error after deployment

I use an API with works fine on my local machine, but not when I deploy it. I can access the API correctly, but however, I am not able to run the sendmail function anymore. This is the code: def is_valid_email(email): if len(email) > 7: …
Data Mastery
  • 1,555
  • 4
  • 18
  • 60
0
votes
1 answer

Only allow expected fields?

My model expects two fields, and I validate my endpoint with that model: config_model = api.model('Configuration', { 'cuvettes_count': fields.Integer, 'pipettes_count': fields.Integer }) # later class ConfigEndpoint(Resource): …
Jonathan Tuzman
  • 11,568
  • 18
  • 69
  • 129