Live data from Hacker News

A Beginner’s Introduction to Python Web Frameworks (2018)

stxnext.com

101–110 of 168 posts

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#102
post #44

This is a short list I have compiled a few months ago, FWIW: New kids on the block: - Starlette https://www.starlette.io - Vibora https://vibora.io - Xweb https://github.com/gaojiuli/xweb - Storm https://github.com/jiajunhuang/storm - Responder http://python-responder.org - Quart https://pgjones.gitlab.io/quart/ - Sanic https://sanic.readthedocs.io - Bocadillo https://bocadilloproject.github.io/ - Japronto https://gi…

Any of those have good Swagger integration? https://swagger.io/

https://github.com/Pylons/pyramid_openapi3

https://github.com/ergo/pyramid_apispec

I'm pretty sure all other popular frameworks have integrations too.

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#103
post #37

Earlier quoted context omitted.

async is more beneficial for when code is primarily network bound. WSGI is thread based which comes with a higher overhead for task switching. So it’s just not as efficient for most web server tasks.

Ok I think I get it, but if your backend is say, making a single API call and sending that result back to the user, then there's no advantage to going async since the user has to wait for that network call anyways, right? Would you use this async then in instances where some of the API calls don't matter to your user?

Python wsgi servers are generally based on processes and not threads since threads would trigger GIL considerations. While your process is making the single API call, the process is not serving anyone else, ergo you can only have so many simultaneous requests in flight as you have workers. Threads have no benefit over asyncio in python due to the GIL and have costs over ascyncio due to setting up the thread context with the OS.

With asyncio based implementations, while the coroutine is waiting for the response on the API call, the process's event loop can check on the coroutine which is handling the network socket and start processing another request. Ideally it should have no impact on the amount of time the original request takes to process but you can see how it might since when the API call resolves, the process may be working on the other request instead of continuing with the original coroutine.

Asynchronous code in general can allow you to extend your bandwidth past the number of concurrent executions your program can maintain (whether they be processes in python or threads in other languages) by doing additional work while it is waiting for something to complete. Ideally it should not cost much in terms of latency.

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#104

Earlier quoted context omitted.

Django's tagline is "The Web framework for perfectionists with deadlines".

.. That comes with a brief documentation of 1941 pages (as of August 20, 2019)..

That's because it comes with a load of built in functionality.

I am sure Flasks documentation is a lot smaller but its essentially just a few parts of Django (it doesn't have a built in ORM from what I understand). Start adding in the documentation for SQL alchemy, documentation for an authentication library and whatever else you need and you will probably start getting something similar but without the guarantee that the pieces will play nicely together.

(Djangos documentation is really good.)

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#105
post #29

We need to write a lot of small APIs in Python for SPAs. We ended up going with FastAPI which utilizes Starlette under the hood. I'm surprised neither of them are mentioned here. Starlette was developed by the same dev who wrote the Django RESTful package. If you mostly just need REST APIs or even GraphQL, it feels far more light and modern than anything in Django and forms some better opinions around things than the…

Do frameworks need to be asynchronous or is it good enough to just spawn threads for background tasks?

[deleted]

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#106

For such a comprehensive list, no mention of tornado?

Yeah. It's odd. We use Tornado for all our API/microservices at work and it's been a pleasure. More and more libraries are getting asyncio support as well and they integrate well with Tornado.

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#107
post #44

Earlier quoted context omitted.

Any of those have good Swagger integration? https://swagger.io/

FastAPI (built on Starlette) essentially generates your OpenAPI docs for free via intuitive use of decorators and type hints/Pydantic models.

+1 for FastAPI. It also has really good documentation

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#108
post #12

I started working with Python around 2013 and I still consider Django the best framework to use. Yes Flask you can pick what you want to use but I have found the supporting libraries to be a bit outdated. Everytime I have used it I feel like I am just gluing together a lot of different pieces and it becomes messy. Django is constantly updated and I have little to no worries about security issues. Edit: And I have bee…

We have a legacy Django app at work. Coming from Rails and living in the npm eco-system for the past few years, Django to me seems like an anti-pattern framework in a death-spiral.

Its likely to be the application. You can write pretty nice Django or horrendously bad Django. It's MVC - essentially the same patten as Rails.

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#109

The post doesn't mention Django's migration system, which is a killer feature. Of course, one should change their database infrequently and deliberately, but it is nonetheless a delight to use, and a feature that is not matched by many other web frameworks, Python-based or otherwise.

> Of course, one should change their database infrequently and deliberately,

I think this attitude leads to a lot of crappy code. It's "safer" just to add a bit more to the application layer than to change the database, but do that enough times and you end up with a mess to compensate for a database design that doesn't model what it needs to. (Learned through experience).

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#110

Are any of these extremely good compared to a framework not written in Python? For example compared to Rails or Phoenix?

Apparently Rails and Django are pretty similar. Rails has a bit more magic, and Django is a bit more explicit. (I have only really used Django but was close to choosing Rails and that's what a lot of articles said when I was researching).
Post reply on HN