Page MenuHomePhabricator

[backend] Investigate API support options
Closed, ResolvedPublic

Description

Flask-RESTX

Flask-RESTful + Flasgger

Flask-Smorest (which incorporates Marshmallow) -- unless there are objections, I'll be moving forward with this option. The other libraries are no longer maintained and, although Flask-Smorest doesn't have the greatest documentation, I've found some resources that allow me to make sense of it.

Other information:
https://www.imaginarycloud.com/blog/flask-python/

Event Timeline

Hannah_Njoroge changed the task status from Open to In Progress.Jan 17 2023, 6:11 AM

After some preliminary investigation, it looks like flask-RESTX has the advantage in that it incorporates Swagger automatically, which will allow for auto-generation of the API documentation, whereas flask-RESTful would require us to install additional packages (e.g., Flasgger).

It also appears that flask-RESTful is no longer actively maintained, which is definitely a strike against it.

However, more digging has revealed that flask-RESTX itself is also only minimally maintained, and there seem to be some ongoing issues around data models and request parsing that are unlikely to be resolved. (See Flask-RESTX Models Re-design.

Flask-RESTX's own documentation admits that there are other packages that do things better (e.g., marshmallow); see the warning at the top of the Request Parsing documentation.

I have uncovered another library, flask-smorest, which does everything that RESTX does and also uses marshmallow and appears to be maintained; as far as I can gather, it seems to be the most au courant of the options.

Possibly stupid question, though: do we need an API library at all?

Possibly stupid question, though: do we need an API library at all?

Not really, but we do need the things that API libraries (ideally) offer:

  • Serialization/Deserialization (Python objects -> JSON -> Python objects)
  • Data parsing of incoming requests
  • Data validation
  • OpenAPI docs, a.k.a Swagger

There's a pretty insightful discussion of different alternatives and pros/cons here: https://fastapi.tiangolo.com/alternatives/

Thank you, that link was very useful. The number of alternatives in this space makes my head spin. It's a shame that we can't just use FastAPI but such is life.

I've found some great resources to help me get my head around flask-smorest and marshmallow, so unless there are objections I'm going to go ahead with that.

NicoleLBee renamed this task from [backend] Investigate Flask-RESTX vs. FlaskRESTful + flasgger for API support to [backend] Investigate API support options.Jan 22 2023, 10:15 AM
NicoleLBee updated the task description. (Show Details)

I've found some great resources to help me get my head around flask-smorest and marshmallow, so unless there are objections I'm going to go ahead with that.

No objections on my side.

NicoleLBee claimed this task.