Why Flask-Restplus is better then using Flask Pluggable views with methods, especially when we use a separate parser like marshmallow (which is a good thing)? Is their any other advantages besides Swagger docs? Right now I decide how to implement an API and my decision for the moment is Flask Method Views + Marshmallow + Webargs + Swagger (Connexion) and it is really interesting to know any other opinions on this.
Flask RESTPlus forces you into its convention, so if you like it, then I'd use it. Of course you'd have more flexibility by just doing things with pluggable views and Marshmallow. Kinda of like the difference between micro web frameworks like Flask and fully featured ones like Django. it just depends on your needs and preferences.
problems running source code. when i run version from git i get the following error: TypeError: create_language() got an unexpected keyword argument 'many' is there a difference with the current versions of flask-restplus and marshmallow ? I see below there is an answer add **kwargs but it hasnt worked, can you confirm whether the code works with current versions ? and if it does what could the problem be?
When I try to use the post method on the app, I get the following error: TypeError: create_language() got an unexpected keyword argument 'many' Any idea what is going on?
I found solution, just add "**kwargs" argument to "create_language" method @post_load def create_language(self, data, **kwargs): return TheLanguage(**data)
I'm really confused. Can someone explain to me like a 3-year-old how I would, for example, work with this in Postman? Lets say I want to post a JSON data from Postman to POST and it looked like this, {'title" : "Hello World", "year": 2005}, how would I: a) Validate all the fields are provided b) Access the titles and year if I need to, in Flask Resplus? Or should I use request.json.get() or request.get_json()?
Why you don't use the built in validating? My whishes are: 1. Defining SQLAlchemy Model 2. Define Dto Model 3. Get should parse sqlalchemy model to json 4. incoming data should be parsed to Dto Model How can i realize that without defining three or more models? With out using over 9000 libraries? Maybe with one or two built in libraries (maybe in restplus built in?)
I've liked it as always, thanks for this. But you are right, the world language to use here is very confusing and the world framework might much more. You can just say "framework attribute" together or ... Use animal names next time :) Your video is so helpful, you put affort but it will confuse developers also just because of this. Thanks Man, you are good and please keep up the good work! :)
Some integration issues. Flask-Marshmallow isn't designed to be used with Flask-RESTPlus (although you can get it to work). Marshmallow is more generic. If they officially add Flask-Marshmallow to Flask-RESTPlus, changing the code will be easy.
#namespace = Namespace(name='College', description=None, path=None, decorators=None, validate=None) api.title = '1111 Catalog API' #api.add_namespace(namespace) college = api.model('College', { 'name' : fields.String('name'), 'short_name' : fields.String('short_name')}) @api.route('/college') class CollegeList(Resource): @api.marshal_with(college) def get(self): return models.College.query.all() @api.route('/college/') class College(Resource): @api.marshal_with(college) def get(self, id): return models.College.query.filter(models.College.id == id).one() Questions: 1.) Is there a better way of doing this? For example, I was thinking to put two get() in the same "College" class with different routing URL's, but Flask restful is not allowing me to do that. 2.) I tried to add namespace because I wanted to have different namespaces for different classes, but the label on Swagger UI is not changing. Any idea? Thanks in advance!
The resources are main objects in Flask-RESTPlus, so it doesn't make sense to have two get endpoints for the same resource. And are you sure you added the namespace to your resources?
Thanks for your reply. I added resources, but I got an error "api.payload not found" so I removed the namespaces and came back to default one. Is there anything I will need to do to have payload available?
Join my free course on the basics of Flask-SQLAlchemy: prettyprinted.com/flasksql
Do you think this method is still necessary now that rest plus has been forked into rest x?
Why Flask-Restplus is better then using Flask Pluggable views with methods, especially when we use a separate parser like marshmallow (which is a good thing)? Is their any other advantages besides Swagger docs? Right now I decide how to implement an API and my decision for the moment is Flask Method Views + Marshmallow + Webargs + Swagger (Connexion) and it is really interesting to know any other opinions on this.
Flask RESTPlus forces you into its convention, so if you like it, then I'd use it. Of course you'd have more flexibility by just doing things with pluggable views and Marshmallow.
Kinda of like the difference between micro web frameworks like Flask and fully featured ones like Django. it just depends on your needs and preferences.
Sir could u explain one example with reqparser please
Generate JSON schema from marshmallow Shema. And use only @response, not @marshall_with. This way you get swagger doc and marshmallow validation
Thanks I'll try that in the future.
Hi thanks for all your videos. It's very helpful ! I am looking some help in integrating java with flask I am looking to existing java jars in flask.
problems running source code. when i run version from git i get the following error:
TypeError: create_language() got an unexpected keyword argument 'many'
is there a difference with the current versions of flask-restplus and marshmallow ? I see below there is an answer add **kwargs but it hasnt worked, can you confirm whether the code works with current versions ? and if it does what could the problem be?
When I try to use the post method on the app, I get the following error:
TypeError: create_language() got an unexpected keyword argument 'many'
Any idea what is going on?
I have a same problem
I found solution, just add "**kwargs" argument to "create_language" method
@post_load
def create_language(self, data, **kwargs):
return TheLanguage(**data)
@Scott Simontacchi you also need to remove data in line languages.append(new_language.data). Correct version is languages.append(new_language)
Thanks again for the great video.
But would you slowing down on upload? Like twice a week or so?
haha I'm trying to figure out the optimal schedule.
Thank you so much for this!
I'm really confused. Can someone explain to me like a 3-year-old how I would, for example, work with this in Postman? Lets say I want to post a JSON data from Postman to POST and it looked like this, {'title" : "Hello World", "year": 2005}, how would I:
a) Validate all the fields are provided
b) Access the titles and year if I need to, in Flask Resplus?
Or should I use request.json.get() or request.get_json()?
Thanks for the great video! Will you also teach how to do GraphQL in Python in the future?
Yeah, that's on my list of topics to cover.
Why you don't use the built in validating?
My whishes are:
1. Defining SQLAlchemy Model
2. Define Dto Model
3. Get should parse sqlalchemy model to json
4. incoming data should be parsed to Dto Model
How can i realize that without defining three or more models?
With out using over 9000 libraries? Maybe with one or two built in libraries (maybe in restplus built in?)
It's going to be deprecated soon. But they said that two years ago, and it's still there, so I'm not sure what they plan on doing.
oh okay ^^ that is bad for a library...
How to handle form data in restplus
4 + Years and still Marshmallow is not integrated with Flask Restx :(
I've liked it as always, thanks for this. But you are right, the world language to use here is very confusing and the world framework might much more. You can just say "framework attribute" together or ... Use animal names next time :) Your video is so helpful, you put affort but it will confuse developers also just because of this. Thanks Man, you are good and please keep up the good work! :)
Yeah, I messed up the names in this one. I'll do better next time.
Ghvughhhhhh
Why use flask-resplus when you can achieve the same with just flask-marshmallow
Just a different way of doing things. Having Swagger is a huge plus as well.
@@prettyprinted would it make sense to just ur marshmallow and flask-swagger instead?
Why marshmallow, and not directly flask_marshmallow?
Some integration issues. Flask-Marshmallow isn't designed to be used with Flask-RESTPlus (although you can get it to work). Marshmallow is more generic. If they officially add Flask-Marshmallow to Flask-RESTPlus, changing the code will be easy.
#namespace = Namespace(name='College', description=None, path=None, decorators=None, validate=None)
api.title = '1111 Catalog API'
#api.add_namespace(namespace)
college = api.model('College', { 'name' : fields.String('name'),
'short_name' : fields.String('short_name')})
@api.route('/college')
class CollegeList(Resource):
@api.marshal_with(college)
def get(self):
return models.College.query.all()
@api.route('/college/')
class College(Resource):
@api.marshal_with(college)
def get(self, id):
return models.College.query.filter(models.College.id == id).one()
Questions:
1.) Is there a better way of doing this? For example, I was thinking to put two get() in the same "College" class with different routing URL's, but Flask restful is not allowing me to do that.
2.) I tried to add namespace because I wanted to have different namespaces for different classes, but the label on Swagger UI is not changing. Any idea?
Thanks in advance!
The resources are main objects in Flask-RESTPlus, so it doesn't make sense to have two get endpoints for the same resource. And are you sure you added the namespace to your resources?
Thanks for your reply. I added resources, but I got an error "api.payload not found" so I removed the namespaces and came back to default one. Is there anything I will need to do to have payload available?