Search code examples
pythonrestflaskflask-restfulmarshmallow

flask-based REST api: marshmallow vs flask-restful


I have gone thru a tone of flask tutorials the last couple of weeks.

From my understanding, to build a simple REST api based on flask, there are (among others) two ways:

  • adopting flask-restful and using it to create Resources that you then expose via the appropriate url/routes and bind them with sqlalchemy models

  • use plain sqlalchemy for the model, and then marshmallow for de/serialization and object serving in json format.

Is there a comparison among these two approaches? I 'm kinda new in the field and the marshmallow approach seemed to be quicker and perhaps easier to follow.

Are there any benefits when it comes to adopting flask-restful compared to the de/serialiation layer of marshmallow?


Solution

  • Marshmallow is a serialization/deserialization library and flask-restful is a package to build REST APIs.

    Yes there are some benefits from using flask-restful:

    • Easy argument parsing
    • Custom error handler
    • Encourages REST best practices

    There is also a package called Flask-Restplus that is based on Flask-resftul but add some features like Swagger doc generation, better error handling etc: https://flask-restplus.readthedocs.io/en/stable/