Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Bottle by FastAPI #2181

Closed
nicolargo opened this issue Nov 5, 2022 · 9 comments
Closed

Replace Bottle by FastAPI #2181

nicolargo opened this issue Nov 5, 2022 · 9 comments
Labels
dependencies Pull requests that update a dependency file enhancement
Milestone

Comments

@nicolargo
Copy link
Owner

Trade-off should be made between the current Bottle Framework and a new one like FastAPI (see https://fastapi.tiangolo.com/#requirements).

@nicolargo nicolargo added enhancement dependencies Pull requests that update a dependency file labels Nov 5, 2022
@nicolargo nicolargo added this to the Glances 4.0.0 milestone Nov 5, 2022
@RazCrimson
Copy link
Collaborator

Another possible option to consider:
https://github.com/starlite-api/starlite

@nicolargo
Copy link
Owner Author

nicolargo commented May 19, 2023

@nicolargo nicolargo changed the title Replace Bottle by FastAPI Replace Bottle by FastAPI or other Framework May 19, 2023
@Tronic
Copy link

Tronic commented May 19, 2023

Consider https://sanic.dev/en/ - one of the fastest Python frameworks (talking about 100k req/s) and has API very similar to FastAPI or Bottle/Flask+async. Already proven, used in large projects (e.g. Italian government Covid tracing app). Can directly run a public web server incl. HTTP/3, and comes with other advanced features while staying low level and unopionated. Just almost nobody seems to know it exists. Disclaimer: I am a developer of it.

@RazCrimson
Copy link
Collaborator

@Tronic

Assuming that the FastAPI are not biased, it might be better to just stick with FastAPI
Ref: https://fastapi.tiangolo.com/alternatives/#sanic

Litestar/Starlite seemed interesting but seems to be quite less used than FastAPI. FastAPI also has a huge userbase with lot of community support, so I think sticking with it would be the best bet in a long term standpoint.

@nicolargo What do you think?

@Tronic
Copy link

Tronic commented May 19, 2023

@RazCrimson Uvicorn (that Starlette and FastAPI run on) is an ASGI server and can be used with Sanic as well. However, the preferred way to run Sanic is using its integrated HTTP server which runs much faster than what is possible via ASGI. That being said, FastAPI can run fairly quick too. I've yet to see useful conclusive benchmarking between the two, and we do not intend to compete with it for users (rather, we are interested on how to awake Flask and Django users, as well as NodeJS Express users, to that there are modern alternatives).

Sanic benchmarks consistently faster than FastAPI and other popular frameworks in these micro benchmarks (that I wouldn't put much value on):
https://www.techempower.com/benchmarks/
https://web-frameworks-benchmark.netlify.app/result

Your application looks like it wouldn't be super heavy on requests, so you might be looking more at how to get your routes setup (FastAPI notably using type annotations for that), or perhaps just setting up a static site with VueJs or alike that talks to the backend via a single websocket endpoint. And then how easy it is to deploy either on localhost or perhaps if you are looking for TLS certificates, possibly also authentication, on a public site. I believe both frameworks are smart enough to avoid the use of callback functions, and to have proper flow control and security to run safely on hostile networks (things that haven't always been certain on earlier frameworks).

@RazCrimson
Copy link
Collaborator

@Tronic

My bad, I should have put that a bit better.

The reason I preferred FastAPI to Sanic was not really the performance but the huge community behind it. So in the end FastAPI would end up being more tested for bugs and vulnerabilities than other frameworks as the larger user base would be having more diverse use cases.

@Tronic
Copy link

Tronic commented May 20, 2023

@RazCrimson Not sure whether you'll get that, as it is a very young framework and only built for JSON APIs (rather than diverse use cases). But yes, it certainly seems more popular at this time and has more active developers, so I understand why you'd go with that.

@nicolargo
Copy link
Owner Author

Work started on branch issue2181

@nicolargo nicolargo changed the title Replace Bottle by FastAPI or other Framework Replace Bottle by FastAPI Dec 16, 2023
nicolargo added a commit that referenced this issue Dec 16, 2023
@nicolargo
Copy link
Owner Author

Merged into develop.

BREAKING CHANGE: API version is now 4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement
Projects
None yet
Development

No branches or pull requests

3 participants