Using Marshmallow with Flask-RESTPlus

Поделиться
HTML-код
  • Опубликовано: 2 ноя 2024

Комментарии • 39

  • @prettyprinted
    @prettyprinted  4 года назад

    Join my free course on the basics of Flask-SQLAlchemy: prettyprinted.com/flasksql

  • @crono782
    @crono782 3 года назад

    Do you think this method is still necessary now that rest plus has been forked into rest x?

  • @maxvas7267
    @maxvas7267 6 лет назад +1

    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.

    • @prettyprinted
      @prettyprinted  6 лет назад +2

      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.

  • @sudheerreddy2074
    @sudheerreddy2074 4 года назад

    Sir could u explain one example with reqparser please

  • @КонстантинПепеляев-м8г

    Generate JSON schema from marshmallow Shema. And use only @response, not @marshall_with. This way you get swagger doc and marshmallow validation

  • @NiteshSingh-yi1xi
    @NiteshSingh-yi1xi 6 лет назад

    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.

  • @dannycorganrg1
    @dannycorganrg1 4 года назад

    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?

  • @focf1981
    @focf1981 5 лет назад +2

    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?

    • @ganiksu01
      @ganiksu01 5 лет назад

      I have a same problem

    • @ganiksu01
      @ganiksu01 5 лет назад +1

      I found solution, just add "**kwargs" argument to "create_language" method
      @post_load
      def create_language(self, data, **kwargs):
      return TheLanguage(**data)

    • @Adamsooon
      @Adamsooon 4 года назад

      @Scott Simontacchi you also need to remove data in line languages.append(new_language.data). Correct version is languages.append(new_language)

  • @herirusmanto
    @herirusmanto 6 лет назад

    Thanks again for the great video.
    But would you slowing down on upload? Like twice a week or so?

    • @prettyprinted
      @prettyprinted  6 лет назад

      haha I'm trying to figure out the optimal schedule.

  • @gibson60
    @gibson60 4 года назад

    Thank you so much for this!

  • @Noldy__
    @Noldy__ 6 лет назад

    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()?

  • @kun2424
    @kun2424 6 лет назад

    Thanks for the great video! Will you also teach how to do GraphQL in Python in the future?

    • @prettyprinted
      @prettyprinted  6 лет назад

      Yeah, that's on my list of topics to cover.

  • @danieldaschle
    @danieldaschle 6 лет назад

    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?)

    • @prettyprinted
      @prettyprinted  6 лет назад

      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.

    • @danieldaschle
      @danieldaschle 6 лет назад

      oh okay ^^ that is bad for a library...

  • @drac8854
    @drac8854 4 года назад

    How to handle form data in restplus

  • @indrocool77
    @indrocool77 2 года назад

    4 + Years and still Marshmallow is not integrated with Flask Restx :(

  • @scicommerce
    @scicommerce 6 лет назад

    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! :)

    • @prettyprinted
      @prettyprinted  6 лет назад

      Yeah, I messed up the names in this one. I'll do better next time.

    • @chakkarapaniv
      @chakkarapaniv 6 лет назад

      Ghvughhhhhh

  • @quechon1
    @quechon1 6 лет назад +4

    Why use flask-resplus when you can achieve the same with just flask-marshmallow

    • @prettyprinted
      @prettyprinted  6 лет назад +2

      Just a different way of doing things. Having Swagger is a huge plus as well.

    • @Gbd279
      @Gbd279 4 года назад

      @@prettyprinted would it make sense to just ur marshmallow and flask-swagger instead?

  • @luisnabais
    @luisnabais 6 лет назад

    Why marshmallow, and not directly flask_marshmallow?

    • @prettyprinted
      @prettyprinted  6 лет назад +1

      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.

  • @puneetja
    @puneetja 6 лет назад

    #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!

    • @prettyprinted
      @prettyprinted  6 лет назад

      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?

    • @puneetja
      @puneetja 6 лет назад

      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?