/flask-webargs-marshmallow-schemas

Flask project gist based on lessons learned from FastAPI using Marshmallow instead of Pydantic.

Primary LanguagePython

flask-webargs-marshmallow-schemas

A simple boilerplate for a Flask API based on my experience with FastAPI but using Marshmallow for schemas instead of Pydantic. Uses decorators for designating schemas for requests and responses as well as decorators for handling endpoint parameters similar to FastAPI's dependency injection with Depends. I also borrowed from FastAPI's boilerplate the CRUD classes to concentrate database access methods for easy re-use and testing.

I do recommend FastAPI if you are starting a new API project and want automatic documentation since this example doesn't show how to do that. I made this since I have personal projects I want to upgrade to use some ideas I've learned since using FastAPI and will implement these ideas into those projects. This may also be useful for those who are happy with Flask yet and want to combine a server-side rendered pages with API endpoints for perhaps some dynamic Javascript elements in the rendered pages. I've also done this with a FastAPI app by mounting the FastAPI app into a Starlette app so Flask is not the only choice for this pattern. But I'll leave error handling between views and API endpoints as an excerise to you. Lastly, this is the type of example I think may help a beginner since it was examples like this that helped me years ago.