Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Franck Kambiwa
@thynquest
hello there
I just learned that flask-restplus is no longer maintained ?
Callam
@cal97g
@thynquest check python-restx/flask-restx
it's a drop in replacement
Harsh Thakur
@harshthakur9030
Hey guys, I want to write a serverless function but write it using flask-restplus. Can someone help me figure out how to do it? I've tried Zappa but that didn't yield the results I was hoping for :/
@SteadBytes @ziirish any idea
Callam
@cal97g
@harshthakur9030 this project is unmaintained.
Sergey Vilgelm
@SVilgelm
@harshthakur9030 How do you see this? The flask-restplus|restx is a Flask's extension that adds support for quickly building REST APIs and Flask is a WSGI web application framework. The both libraries are used to build a web server. I'm not sure how can you use them to implement a server less function.
John Chittum
@j5awry

@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
@am17torres
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.
ns=api.namespace('todo')
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)
})

@ns.route('/')
class TodoList(Resource):
    @ns.doc('create_todo')
    @ns.expect(child1, child2, validate=True)
    def post(self):
        return api.payload
Harsh Thakur
@harshthakur9030
@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
@j5awry

@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.

https://www.martinfowler.com/articles/serverless.html

Justvuur
@Justvuur
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
@flayman
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:
@api.route('/my-resource/')
class MyResource(Resource):
    @api.response(400, 'Validation error')
    @api.marshal_with(model, code=201, description='Object created')
    def post(self):
        pass
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
@dc_pwc_gitlab
This message was deleted
Guto Maia
@gutomaia

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,
}


fields.List(fields.Polymorph(mapping))

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

Guto Maia
@gutomaia
hi @noirbizarre
Nitendra Singh Yadav
@nitendra-yadav
hi @all, is there any good library in python for users and subscription management?
Justvuur
@Justvuur
@flayman Thanks but would it be possible to change the messing in the method/function depending on the case/outcome?
Matt Flaherty
@flayman
@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
@nitendra-yadav
{{{
class ObjectIdVal(fields.Raw):
schema_type = 'string'
schema_example = '54f0e5aa313f5d824680d'
def format(self, id):
try:
x = bson.objectid.ObjectId.is_valid(id)
print(x)
return x
except ValueError as ve:
raise MarshallingError(ve)
def validate(self, id):
"""
Validate the value. return True if valid
"""
print(id)
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
bkranendonk
@bkranendonk

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?

Python Hub
@pythonhubpy

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

class SchemaValidationError(Exception):
pass

class UpdatingUserError(Exception):
pass

class UserNotExistsError(Exception):
pass

class EmailAlreadyExistsError(Exception):
pass

class UnauthorizedError(Exception):
pass

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
@j5awry
if asking about restx, go here: https://gitter.im/python-restx/community
chama-chomo
@chama-chomo
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
@ankajain
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: http://0.0.0.0:5001 (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
@ankajain
DockerFile config

FROM python:3.8-slim-buster

EXPOSE 5001

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

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

WORKDIR /app
ADD . /app

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

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

requirement file only having this
flask==1.1.2
gunicorn==20.0.4
flask-restplus==0.13.0
Any help please.
Ugur B.
@ayakzob
hi,
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
@henshalb
is there any option to add tags for flask-restplus, swagger docs?
realburi
@realburi
Hi guys
is there an opposite function of flask_resplus.abort
tankeryang
@tankeryang
@henshalb use Namespace
Narate Pokasub
@narate.pokasub_gitlab
I try to use flask_limit with flask_resplus. So anyone can suggest the example or document that support namespace
Balaji
@bala4604
I tried to implement my flask-restplus program but i couldn't even access restplus import and throwing the following error
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\
init__.py)
pip freeze
aniso8601==9.0.1
attrs==21.2.0
click==8.0.1
colorama==0.4.4
Flask==2.0.1
flask-restplus==0.13.0
itsdangerous==2.0.1
Jinja2==3.0.1
jsonschema==3.2.0
MarkupSafe==2.0.1
pyrsistent==0.17.3
pytz==2021.1
six==1.16.0
Werkzeug==2.0.1
Anyone help me to solve the issue
Anik Chowdhury
@nikitow1
Screenshot 2021-06-02 at 10.53.32 AM.png
I am newbie in flask and flask rest api. Can anyone suggest how to implement this dropdown like this in swagger?
Henshal B
@henshalb:matrix.org
[m]
@bala4604: you've to activate the virtual environment first