Micro-frameworks are all the rage lately. Though they've doubtless existed for as long as Python web development has been taking place, the recent release of bubble, juno, and now Flask have more people talking about them.
I've been fighting with the complexities of the major frameworks for a while now, lately getting fed up with the shocking list of dependencies brought in by TurboGears2, and fighting with Pylons and its view of how I should do unit testing and many other things.
I wanted to try something lighter weight in setting up this new site, which was initially running on a 64MB VPS running Ubuntu 9.04. Pylons was incapable of running in this environment, as merely launching it with the default demo site consumed all available memory! (Note that this VPS allows a reasonable amount of "burst" RAM to be temporarily used, but provides no swap space. Using up memory leads to a hard failure and kills the app.) So I was curious how well the micro-frameworks would do, and how they would stack up against each other.
What follows is a very simple comparison of memory usage and performance of three recent micro-frameworks. The test program was basically "Hello world", taken directly off each framework's web site and adjusted only to ensure the Content-Length was the same. (Note that the header lengths were slightly different: flask sent 15 bytes more because it included the charset (utf-8) in the Content-Type header.)
Framework | Memory (K) | Performance (tps) |
---|---|---|
Bottle 0.6.4 | 8900 | 1680 |
Flask 0.1 | 14300 | 1220 |
Juno 0.1.2 | 16350 | 1570 |
All three frameworks loaded the CPU to about the same degree.
I don't think it's right to offer benchmark results without some comment on qualitative aspects.
Bottle comes in a single file (39K) and has no dependencies outside the standard library for basic operation. It can integrate with WSGI, CherryPy, Flup, Paste, and Fapws. It features auto-reload and supports several popular templating engines. The source is clean but has no tests included. It clocks in at 844 lines of code plus 181 doc/comment lines.
Flask itself is a single file (25K) but requires Werkzeug (which isn't tiny) and installs Jinja2 (also not small) even if you don't plan to use it. Of the code in that file, over half is comments: only 215 lines of code, 376 doc/comment lines! As it builds on Werkzeug, you can likely make use of most of the functionality included in that package.
Juno is also a single file (31K) with no non-stdlib dependencies for basic operation. You can also run behind WSGI, SCGI or FCGI (with Flup), or Google appengine. The code appears clean, reasonably commented and organized, with no automated tests included. It manages what it does in only 536 lines of code, with 168 doc/comment lines.