Live data from Hacker News

Ask HN: Best Python web framework

news.ycombinator.com

51–60 of 110 posts

Re: Ask HN: Best Python web framework

#52
post #44
post #37

Pyramid. http://en.wikipedia.org/wiki/Pyramid_%28web_framework%29 * faster. * better quality (100% statement coverage via unit tests) * supports latest python. * great documentation (including free up to date book). There's also a separate pyramid cookbook. * simplicity. If you just see a pyramid app, you can dive right in fairly easily without learning lots of alien stuff. * sensible defaults, and you can choose to…

As an alternative viewpoint * It's complicated * It doesn't really do much for you (have to spend lots of effort/time/learning plumbing in all the 3rd party libs) * Lacks sensible defaults for many things * Documentation is rather lacking. Oh, there's tons of it, but it's rather maze-like and hard to use if you don't actually understand the system. High-level overview/cookbook type stuff is severely lacking.

Touché.

Pyramid will:

* get you laid.

* help you take over the world.

* bring about world peace.

* 100% compatible with emacs, vim, textmate, and even eclipse.

* enterprise mumble mumble certified.

* tool of choice for the coolest startups in the world.

* Compatible with multiple currencies, $ £ and €. So you can make three times as much money.

* venture capitalists prefer it. 'I will chose companies that use pyramid, over those that use Django.' -- pg

Re: Ask HN: Best Python web framework

#53

I really like bottle.py [1]. I've used it for a couple of different projects; although not fundamentally different from web.py or flask, it seems to just "make sense". [1] http://bottlepy.org/docs/stable/ An example from their website: from bottle import get, post, request @get('/login') # or @route('/login') def login_form(): return ''' ''' @post('/login') # or @route('/login', method='POST') def login_submit(): nam…

PHP guy here, don't know much about other languages, but seeing HTML mixed in with code is usually a bad code smell. Is this type of thing common in Python?

This is a simple example to make a point about the simplicity of using bottle, a python micro-framework contained in a single file with all the stuff you need for simple web projects (like routing, templates, various utilities and even a test server).

Re: Ask HN: Best Python web framework

#54
post #46

Earlier quoted context omitted.

> I can't imagine that the benefits would outweigh the disadvantages of having to deal with two frameworks instead of one. Separation of concerns, loose coupling. I tended to find (in the few Django projects I worked on), that models were frequently accessed outside the app that created and owned the model. The subsequent dependency diagram would be spaghetti. We had apps for each significant feature area, and when w…

How do you handle "foreign key references" between modules in your new approach (using APIs to decouple?).

That's one of the fun issues with service oriented architecture.

You either choose high-chatter and low complexity, or low-chatter and high complexity. As high-chatter is also a decrease in performance (mostly due to JSON serialisation/deserialisation and HTTP requests), we opted for low-chatter.

Resources that were a composite of other resources had their own knowledge of how they were composed, and generated their own IDs to save that knowledge. Each new composition resource got it's own Accept header identifier as a result.

Within that composition resource, there wasn't just knowledge of "I'm composed of x:17 and y:3", but also knowledge of how to search across the underlying services. This could be to call search on the underlying service if one side of the composition was dominant in applying the filter to the dataset.

Where it was trivial, a search index belonging to the composed service was used. And because this duplicates data from the underlying resources, messaging was put into the underlying service to notify the composed service of changes that affect searches.

For simplicity you can just imagine that we had some kind of table in the composed service, with ID on each row that because the ID of the composed resource, and that we could search that table, and that messaging magic kept that table in sync.

We could do all of this because we owned all of the services. If we didn't, then I imagine we would have followed a similar path to http://ql.io/

Re: Ask HN: Best Python web framework

#55

I really like bottle.py [1]. I've used it for a couple of different projects; although not fundamentally different from web.py or flask, it seems to just "make sense". [1] http://bottlepy.org/docs/stable/ An example from their website: from bottle import get, post, request @get('/login') # or @route('/login') def login_form(): return ''' ''' @post('/login') # or @route('/login', method='POST') def login_submit(): nam…

PHP guy here, don't know much about other languages, but seeing HTML mixed in with code is usually a bad code smell. Is this type of thing common in Python?

Not as bad as those examples you just saw, but as others already said, those are mainly illustrative. Beyond that, it's a matter of template engines and most frameworks allow you to choose one.

Generally you won't see PHP/JSP levels of code, but the more popular engines do allow quite a bit of logic, i.e. don't adhere to StringTemplate-level purity[1].

[1]: http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf

Re: Ask HN: Best Python web framework

#56
post #47
post #36

Earlier quoted context omitted.

Disagree, Django Rest Framework and TastyPie make REST APIs effortless: write Django models, register them with the REST plugin, hook the plugin to your main URL structure. They're a really good example of how Django enables reuse. Implementation-wise they both hook into the model framework and the form framework, although you can swap out those parts if your data lives elsewhere.

I see what you're saying. But I disagree that: Database = Model = Resource

There's flexibility. I've gotten a lot of mileage of closely-related models inlined into a parent model to form a single resource (resource relationships annotated with full=True with TastyPie), but one isn't limited to that either; http://django-tastypie.rtfd.org/ outlines the possibilities better than a short comment could.

Re: Ask HN: Best Python web framework

#57

CherryPy has had Python 3 support for quite a while now. Not many Python frameworks have that. Pylons just got it, so I'd go with CherryPy. You can get WebSocket support too, and documentation is OK.

I see so much stuff about flask and bottle, but not much about cherrypy, what do those do for you that cherrypy doesn't? cherry py has always worked well for me, I'm a fan.

Re: Ask HN: Best Python web framework

#58
Flask is at about the right level of abstraction in the age of polyglot DBs and the JS movement to put the presentation in the browser. Flask gets out of your way and makes it easy to adapt to the changing environment without having to hack your way out of a monolith.

Diesel (http://diesel.io/) has piqued my interest as of late -- it's a high-concurrency, coroutine-based framework with Flask under the hood, by the guys at Bump.

The next-gen Python Web frameworks will probably be non-WSGI because WSGI doesn't support WebSockets.

One approach would be a ZeroMQ-based framework like Brubeck (http://brubeck.io/) behind Mongrel2 (http://mongrel2.org/). But AFAIK, WebSocket support is not yet fully baked into Mongrel2. The handshake still needs to happen on the handler side.

Re: Ask HN: Best Python web framework

#59
post #17

Tornado. Built-in async operations. Not standing in your way. Rapid developments. Huge community. Simply works. Simple, yet rich.

Don't use Tornado unless you plan to build a full SOA. Python drivers are blocking by default and Tornado offers no support for that, meaning Tornado blocks if you have database calls in your code.

Use gevent. Huge community. Simply works and simply scales. And it makes all your blocking calls nonblocking automatically. Tornado just blocks.

Re: Ask HN: Best Python web framework

#60
Try Brubeck. It's a Python web framework built around Gevent, DictShield and ZeroMQ. It communicates with Mongrel2, it's web server, via ZeroMQ sockets so even the annoying design of WSGI is moved out of the way.

It converts your blocking calls to nonblocking, has no spaghetti code filled with callback shenanigans, and can even generate a full REST API for you.

https://github.com/j2labs/brubeck

Post reply on HN