5 Smooth Python Web-Frameworks For The Modern Developer | by Emmett Boudreau | Towards Data Science

Around a month ago, I wrote a short article where I highlighted some of my favorite, old-fashioned and lightweight alternatives to Flask and Django that I like to use for deploying endpoints. Though this was certainly a list of some great web-frameworks, they were more light-weight-centric and old-fashioned than options that would likely appeal to the modern Python Data Scientist or developer. As a result of this article, I received several amazing responses enlightening me on even more great options for deploying endpoints using Python. Some of these I was familiar with, but others were entirely new to me, and it was exciting to try these new modules out and use their cool features! If you would like to read the previous article, here it is:
towardsdatascience.com
Starting off our list is a web-framework that follows the same methodology as many of the modules that I love. FastAPI is a Python web-framework that is focused on being light and speedy. One thing that I really did enjoy with FastAPI was just how quick and easy it was to develop with. This is especially useful for endpoints, since there isn’t usually a lot to them besides logic and you most likely don’t need all of the fluff that comes with something like Django or TurboGears in order to create.
FastAPI also has really great documentation, making it easy to learn. This is especially true when compounded with how easy and simple it is to use. The Fast in FastAPI is representative of both the speed that it takes to develop APIs and the speed of the returns of those APIs. It is also based on the open standards that have been orchestrated for API creation, so similar to other web-frameworks you will get all of the tools you could possibly need for transferring data in one convenient package.
As for syntax, FastAPI takes a very Flask-like approach to creating endpoints. This is for good reason, as Flask is another framework that is really great at keeping things particularly small, yet flexible.
from fastapi import FastAPIapp = FastAPI()   @app.get("/") async def root():     return {"message": "Hello World"}
Tornado is not only a great web-framework, but it is also an asynchronous networking library. With this special feature, Tornado is able to serve to thousands of open connections. This is because tornado uses a non-blocking network in and out stream. This makes Tornado incredibly useful for solutions that need to be enormous and scalable!
Tornado is actually a lot different to most other Python web-frameworks, as it doesn’t run on WSGI. While this means that you might be a little more limited on web-server options, Tornado comes with its own pre-packaged server that can get you up and running in no time. While I do love Tornado, something to note is that I did encounter a lot more bugs when trying to deploy it with NGINX, and at some points it was downright frustrating to get NGINX to route to the proper location. I also had this problem with Genie for Julia, so I’m not exactly sure what causes it, but if you’re using Tornado then you might want to try setting up an Apache server, rather than an NGINX server.
In terms of syntax, Tornado takes a very Turbo-Gears-like approach to routing. Using Tornado, rather than putting logic in routes you will often build classes to handle responses on those routes, like this example from their documentation:
import tornado.ioloopimport tornado.webclass MainHandler(tornado.web.RequestHandler):    def get(self):        self.write("Hello, world")def make_app():    return tornado.web.Application([        (r"/", MainHandler),    ])if __name__ == "__main__":    app = make_app()    app.listen(8888)    tornado.ioloop.IOLoop.current().start()
Pyramid is among the web-frameworks that I subjectively really enjoyed using on this list. What is so great about Pyramid? While Pyramid adheres to the light-weight idea and provides very simple ways to make endpoints quickly with minimal code, it also includes all of the features you might need if you ever intend to scale up the operation.
Among the greatest benefits touted by Pyramid is scalability. Pyramid can be both basic and complex, and that is something that might appeal to a data-scientist who may want to expand on their endpoint in the future. In terms of syntax, Pyramid is about in line with the same methodology as Tornado. It follows the object-oriented paradigm till the end, which can be a great thing and a bad thing.
from wsgiref.simple_server import make_serverfrom pyramid.config import Configurator from pyramid.response import Response  def hello_world(request):     return Response('Hello World!')if __name__ == '__main__':     with Configurator() as config:           config.add_route('hello', '/')        config.add_view(hello_world, route_name='hello')                 app = config.make_wsgi_app()        server = make_server('0.0.0.0', 6543, app)        server.serve_forever()
Don’t let Quart’s logo fool you, it is more related to the module Flash than it is to Bottle. Quart is essentially a combination of two web-frameworks put into one module:
Asyncio and Flask.
Which is a fantastic thing because the combination of these two make for a lethal combination! Quart is lightweight, like Flask, but also contains a full list of asynchronous features that you might expect from something like Tornado. This is another one that I subjectively really enjoyed. Quart feels like a slightly beefed-up Flask that doesn’t compromise speed or ease-of-use in the process of adding more features. Funny enough, the Quart documentation actually recommends that you go and visit the Flask documentation, which I think really speaks to its forked nature.
from quart import Quartapp = Quart(__name__)@app.route('/')async def hello():    return 'hello'app.run()
If you’ve ever wanted an asynchronous Flask, Quart is the framework for you!
Now it is time for something a little different; a black sheep, if you will.
(I’m sorry, bad joke.)
Black Sheep is a web-framework inspired by wonderful tools like ASP.NET and Flask that can be used to easily create event-based web applications. With this in mind, I don’t really understand why its called Black Sheep, because the syntax and methodology behind the framework are pretty much identical to Flask.
from datetime import datetimefrom blacksheep.server import Applicationfrom blacksheep.server.responses import textapp = Application()@app.route('/')async def home(request):    return text(f'Hello, World! {datetime.utcnow().isoformat()}')
Like Quart, Black Sheep includes fantastic tools for synchronization and creating non-blocking endpoints across the web. Overall it is certainly a great framework to use, but very similar to Quart — so if you use one you have pretty much used them both, at least as far as I can tell. So still I ask the question,
“ How is that a black sheep?”
(Maybe i’m looking to far into this naming scheme...)
So there you have it, there are some much more modern and well-used web-frameworks that are sure to help you deploy your new endpoints. Though in my opinion, they are all worth adding, if I had to choose one I’d probably go with FastAPI. FastAPI is simple, light-weight, and as the name implies; fast. However, this isn’t to say that FastAPI would be the best option in every case. No application could possibly break ground and tick all the boxes at once, and with that in mind, I would decide what the best features that you will need for your specific case are and choose based on that rather than subjective opinion.
Overall, I’d say all of them are worth adding and trying if you have the storage to facilitate them. In the future, I may do some speed tests on request responses to see what kind of gains we can actually get and quantify the speed claims often made by these frameworks.