Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
John Chittum

@harshthakur9030 1) use python-restx not restplus. 2) never done serverless, as I've always done much larger things. Reading this guide made sense: https://medium.com/@Twistacz/flask-serverless-api-in-aws-lambda-the-easy-way-a445a8805028

however I'd have serious doubts about the self-documenting OpenAPI part working properly on serverless. I haven't run across anyone doing it yet

Anthony Torres
Hi all. I'm having some issues configuring flask-restplus to expect a polymorphic input payload on a post route. Does anyone have reference material on how to get this to work?
The two problems I'm facing:
  • api.inherit() doesn't include the model in the schema spec unless I add the model to an ns.expect
  • ns.expect(child1, child2, validate=True) is trying to validate the input payload against both children instead of either or.
parent = api.model('Parent', {
    'name': fields.String,
    'type': fields.String(discriminator=True)

child1 = api.inherit('Child1', parent, {
    'extra': fields.String(required=True)

child2 = api.inherit('Child2', parent, {
    'extra2': fields.String(required=True)

class TodoList(Resource):
    @ns.expect(child1, child2, validate=True)
    def post(self):
        return api.payload
Harsh Thakur
@j5awry I have noticed the OpenAPI thing too and I'm pretty new to serverless. Why don't people document their API in serverless? How would another developer know the functionality the orignal developer created?
John Chittum

@harshthakur9030 I think some of it is not clearly defining serverless, and part of it is from a saving perspective. If you're doing serverless via something like AWS Lambda, they're meant to be fast running functions that spin up and down. long running tasks will end up costing far more than a traditional AWS VM. Having the continuous running service (the openAPI documentation on a continuous webserver) is probably far more expensive.

I haven't really looked at Amazon APIGateway, or other similar services, to see if there is some sort of API documentation service in them. When I hear serverless, I generally think of either Lambdas, which should be small and fast, or something that's more Backend as a Service oriented, with most logic in the client.


Hi guys, Hope everyone is well and safe! Thanks for this awesome tool! I really enjoy using it. Quick question, is there a way to return a 200 status code with a status message and the json response body? I know there is a way for errors/aborts etc. Just wondering... Got an issue where the POST was performed but I need a warning message to be displayed.
Matt Flaherty
Hi @Justvuur. I may be misunderstanding, but returning a custom message with a status code is simple. There is a parameter for description in the @api.response() and and optional one in @api.marshal_with() decorators. See the following example from the documentation:
class MyResource(Resource):
    @api.response(400, 'Validation error')
    @api.marshal_with(model, code=201, description='Object created')
    def post(self):
Hello all. A few of you know me. I've contributed a little bit of code to flask-restplus in the past. I would like to contribute more to this project now and I have time on my hands since I've been furloughed from my job. Please let me know of anything in particular that needs doing or I'm happy to join a major rewrite effort. Thanks.
David Cannings
This message was deleted
Guto Maia

Hi @Justvuur, i'm facing some error on trying to create a Polymorph List in the response of a service (ex: fields.List(fields.Polymorph(mapping))).

parent_fields = {
    'index': fields.Integer(description='index')

parent = ns.model('Parent', parent_fields)

child1_fields = {
    'attr': fields.String(required=True, description='attr'),

child1 = parent.inherit('Child1', child1_fields)

child2_fields = {
    'attr': fields.String(required=True, description='attr'),

child2 = parent.inherit('Child2', child2_fields)

mapping = {
    child1: child1_fields,
    child2: child2_fields,


That gives a TypeError " TypeError: unhashable type: 'Model'".

Guto Maia
hi @noirbizarre
Nitendra Singh Yadav
hi @all, is there any good library in python for users and subscription management?
@flayman Thanks but would it be possible to change the messing in the method/function depending on the case/outcome?
Matt Flaherty
@Justvuur, it's trivial if you want to use a different status code for each outcome. You register each response. If you want to use the same code and different messages, then it doesn't make sense to document them
Nitendra Singh Yadav
class ObjectIdVal(fields.Raw):
schema_type = 'string'
schema_example = '54f0e5aa313f5d824680d'
def format(self, id):
x = bson.objectid.ObjectId.is_valid(id)
return x
except ValueError as ve:
raise MarshallingError(ve)
def validate(self, id):
Validate the value. return True if valid
return False
hey @noirbizarre , I am unable to get any value in print when adding a field in my model, also its not validating a input string as per the code in format method

Hey there users and devs, thanks for RestPlus which is an awesome Flask module.

It seems like an @property method can't be formatted by Marshal as the JSON key returns null, is this correct?


Hey, guys, I need your help, I have a class which consists of all my error
class InternalServerError(Exception):

class SchemaValidationError(Exception):

class UpdatingUserError(Exception):

class UserNotExistsError(Exception):

class EmailAlreadyExistsError(Exception):

class UnauthorizedError(Exception):

errors = {
"InternalServerError": {
"message": "Something went wrong",
"status": 500
"SchemaValidationError": {
"message": "Request is missing required fields",
"status": 400
"UpdatingUserError": {
"message": "Updating user data is forbidden",
"status": 403
"UserNotExistsError": {
"message": "The user is not registered",
"status": 400
"EmailAlreadyExistsError": {
"message": "User with given email address already exists",
"status": 400
"UnauthorizedError": {
"message": "Invalid username or password",
"status": 401
How can I add this to my API

How can I do this, In flask-restful I have an option to add a class of errors but in restx I don't know how to do that.
John Chittum
if asking about restx, go here: https://gitter.im/python-restx/community
Hi, I'm using @api.resource decorator for endpoint routing in Flask, what I'm not able to figure out is how to accept some parameter in one of the resource methods only (e.g. def get(self, task_id)). Is there any other way other than using api.add_resource... ? Thanks
Akanksha Jain
Hi @all, I am trying Flask-restplus, gunicorn on Docker. Locally endpoint works. But with Docker endpoint always giving 404 error within container as well as directly with endpoint.
Any suggestion or anything which I can check. I tried all the available options posted on google. But nothing is working
No error message nothing in the logs .
[2020-10-28 10:29:58 +0000] [1] [INFO] Starting gunicorn 20.0.4
[2020-10-28 10:29:58 +0000] [1] [INFO] Listening at: (1)
[2020-10-28 10:29:58 +0000] [1] [INFO] Using worker: sync
[2020-10-28 10:29:58 +0000] [7] [INFO] Booting worker with pid: 7
[2020-10-28 10:42:04 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:7)
[2020-10-28 10:42:04 +0000] [8] [INFO] Booting worker with pid: 8
Akanksha Jain
DockerFile config

FROM python:3.8-slim-buster



ADD requirements.txt .
RUN python -m pip install -r requirements.txt

ADD . /app

RUN useradd appuser && chown -R appuser /app
USER appuser

CMD ["gunicorn", "--bind", "", "app:app"]

requirement file only having this
Any help please.
Ugur B.
when do we need to register/create a model through a Namespace and not through an API? I only use models with the marshal_with decorator and it takes the instance as the argument. Are we require to register the model first to be able to use it in the decorator?
Henshal B
is there any option to add tags for flask-restplus, swagger docs?
Hi guys
is there an opposite function of flask_resplus.abort
@henshalb use Namespace
Narate Pokasub
I try to use flask_limit with flask_resplus. So anyone can suggest the example or document that support namespace
I tried to implement my flask-restplus program but i couldn't even access restplus import and throwing the following error
3 replies
Traceback (most recent call last):
File "D:\crudapi\app.py", line 2, in <module>
from flask_restplus import Api
File "D:\crudapi\venv\lib\site-packages\flask_restplus__init.py", line 4, in <module>
from . import fields, reqparse, apidoc, inputs, cors
File "D:\crudapi\venv\lib\site-packages\flask_restplus\fields.py", line 17, in <module>
from werkzeug import cached_property
ImportError: cannot import name 'cached_property' from 'werkzeug' (D:\crudapi\venv\lib\site-packages\werkzeug\
pip freeze
Anyone help me to solve the issue
Anik Chowdhury
Screenshot 2021-06-02 at 10.53.32 AM.png
3 replies
I am newbie in flask and flask rest api. Can anyone suggest how to implement this dropdown like this in swagger?
Henshal B
@bala4604: you've to activate the virtual environment first
Or downgrade Werkzeug
Or switch to flask restx
Hello, is possible to configure fields with required tag to not accept empty values?
Drei Quevada
Hello everyone. This might be trivial to some but has anyone implemented a stable implementation to filter model fields that we only want to use, let's say from a page? For example, I have a flask model (SQLAlchemy) of Person with fields: name, age, birthdate, group . I would like to send a request that has a params data for the fields that I only want to get from a Person model (e.g. name and group). It's easy to implement for unnested fields but for example, I further want to specify the fields that I want for the group field (e.g. I only want the group ID). I'm not asking for a code, rather a stable structure/architecture on how to implement this. Thank you for the help!
Peter Bittner
I'm looking for an example of how to write unit tests for API endpoints, TDD style. The docs don't seem to explain this, and it's not immediately obvious how to do it (because you need to initialize the request context first, before you call the Resoucemembers for the API verbs (e.g. get, post, delete).
Peter Bittner

My take is:

def test_resource_verbs():
    app = Flask(__name__)
    endpoint = MyNewEndpoint()

    with app.test_request_context():

Does that make sense? - There seems to be no need to involve flask_restplus.

Peter Bittner

Unit testing question: When I use the marshal_with decorator I get the following error with my unit tests:

    def wrapper(*args, **kwargs):
        resp = f(*args, **kwargs)
        mask = self.mask
        if has_app_context():
>           mask_header = current_app.config['RESTPLUS_MASK_HEADER']
E           KeyError: 'RESTPLUS_MASK_HEADER'

My API class looks roughly like this:

class FooBar(Resource):

    def get(self):

Without the annotation the tests pass. What do I need to add to the test setup to make the current_app.config complete and working?

Peter Bittner
The solution was to set up the flask-restplus application completely (just as in the actual application).
I ended up using a Pytest fixture to avoid repetition, e.g.
def flask():
    api = Api(Flask(__name__))
    return api.app
def test_resource_verbs(flask):
    endpoint = FooBar()
    with flask.test_request_context():