Live data from Hacker News

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

stxnext.com

31–40 of 168 posts

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

#31
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?

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.

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

#32
post #25
post #11

Earlier quoted context omitted.

Why, a Docker container. Yes, even on Windows. Pack up everything into a single image, downloadable from nearly anywhere. Your web server (which likely also terminates TLS) has to have fastcgi support, you configure the fastcgi and database ports, maybe mount a directory with config files into the container, and that's it.

>Yes, even on Windows. This would require you to run your containers on Windows servers right? Not much reason to do that anymore. Instead should just containerize as part of deployment pipeline

Sometimes all you have is a Windows box. You can either run Linux in a VM on it, or use WSL, or run native Windows containers which are a thing. Imagine that you have a binary dependency which is Windows-specific.

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

#33
post #20

Earlier quoted context omitted.

It's also a myth that Django makes it difficult to pick and choose. For example, this article fails to mention that Django includes support for alternative template engines, including the popular Jinja2. Of course, if you choose not to use a feature like the ORM, you won't get any of the benefits of that feature- but Django doesn't get in your way or make it difficult in any way to do so. You can use as many differen…

Everything you wrote is true, however I think using another ORM in Django is asking for trouble, or at least it's missing a lot of the benefit of Django. The way models work with admin, forms, etc is to me what makes Django so efficient. Also, you don't get much by switching Django templates to Jinja.

I did write a Django project with SQL Alchemy and without any ORM whatsoever.

It made sense because it was database-heavy and UI-light.

Yes, you have to do a bit more when producing forms. You have to do it anyway if your DB operations are not simple CRUD.

Sure you lose much of admin stuff, too.

Django is a framework, a structure where you add (preferably small) pieces of your code to customize its behavior. If what you are building deviates seriously from what the framework was intended for, it quickly becomes more of nuisance than help. But within its subject area, a framework is highly efficient.

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

#34

For such a comprehensive list, no mention of tornado?

That surprised me too. IMHO Tornado should be #3 after Django and Flask since AFAIK it has the best built-in support for writing hybrid HTTP/WebSocket servers in Python.

I use Tornado to serve the WebSocket backend for https://www.slickdns.com/live/. I've also used Django Channels to add WebSocket support to a Django app and found it very cumbersome compared to Tornado.

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

#35
I was forced to encounter Web2Py in an open-source project several years ago. It was awful. Besides the fact that it's stuck in Python 2 (seriously, even today?), it had a lot of bizarre design decisions. For instance, it loaded controllers by concatenating files in a directory - alphabetically. I know Python's import system can confuse some folks, but surely there was a better way. The whole thing left a very sour taste in my mouth, so I rewrote the application in Flask - unfortunately, the lead developers didn't seem interested in my fork. I've moved far away from their project, but I'm not sure what they're going to do come 2020.

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

#36
post #18

Earlier quoted context omitted.

Thanks for pointing to Starlette, I didn't know it and it looks interesting. I completely agree with you on Django. I've had the chance to implement an e-commerce solution in Flask and another one in Django and the process has been a lot easier and faster with Django. You just can't beat having all the basic tools bundled and configured, along with one central documentation.

Just curious, what are you using as a payments solution for an e-commerce site in Django? I've yet to find a solid implementation for that, though I guess diving into Saleor and picking out parts of that implementation is the best choice?

We had to integrate the solution of our bank (see https://paiement.systempay.fr/doc/en-EN/form-payment/quick-s...), which was not very complicated since it's basically just a form, a hmac signature and a return URL.

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

#37
post #29

Earlier quoted context omitted.

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

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?

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

#38
post #35

I was forced to encounter Web2Py in an open-source project several years ago. It was awful. Besides the fact that it's stuck in Python 2 (seriously, even today?), it had a lot of bizarre design decisions. For instance, it loaded controllers by concatenating files in a directory - alphabetically. I know Python's import system can confuse some folks, but surely there was a better way. The whole thing left a very sour t…

I LOVE Web2py! I use it for pretty much all of my projects. It is the only Python framework that is super easy to use, has enough "batteries included" but not too much, super simple and super powerful templating, decent migrations, simple data access layer not complicated ORM, no import hell, implicit routing.

Developer has a new effort underway that is a little more "pythonic": https://github.com/web2py/py4web

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

#39
post #35

I was forced to encounter Web2Py in an open-source project several years ago. It was awful. Besides the fact that it's stuck in Python 2 (seriously, even today?), it had a lot of bizarre design decisions. For instance, it loaded controllers by concatenating files in a directory - alphabetically. I know Python's import system can confuse some folks, but surely there was a better way. The whole thing left a very sour t…

Web2Py is eminently Python 3 compatible these days.

I have used it for largish projects, and consider it very much not awful at all, but I am aware of opinions on the subject often being polarised (Flask creator Armin Ronacher for one has spent a lot of words and energy badmouthing Web2Py - a behaviour I personally find somewhat unbecoming).

For those not caught up in dogma too much: Try it. Got a lot going for it, and the docs are superb.

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

#40
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://github.com/squeaky-pl/japronto

    The old guard:
    - Flask http://flask.pocoo.org
    - Tornado http://www.tornadoweb.org
    - Falcon https://falconframework.org/
    - Bottle https://bottlepy.org
    - Pyramid https://trypyramid.com/
    - CherryPy https://cherrypy.org/

    Less known older ones:
    - Wheezy Web https://pythonhosted.org/wheezy.web/
    - API Hour https://pythonhosted.org/api_hour/
    - Morepath https://morepath.readthedocs.io/en/latest/toc.html
    - Klein https://github.com/twisted/klein
    - Weppy http://weppy.org/
Post reply on HN