15 ms·
Bottle: Single-File Python Web Framework
- deleted 15y ago[deleted]
- rednaught 15y agoBottle has been around for a while and is great. But is there something new or about to reach proverbial "1.0" status? For those interested in single-file frameworks, there is also Mojolicious in Perl and Fat-Free in PHP.
- deleted 15y ago[deleted]
- drats 15y agoThe disqus comments on the page are entirely correct: it should come standard with python (or something like it). I've used it a few times and it's just elegant and would match "batteries included" perfectly.
- briancurtin 15y agoA full web framework is not something you want to come standard with Python. Putting Bottle, Flask, Django, {your_favorite} inside the standard library would pretty much kill it. Development would screech almost to a halt since Python generally releases less often than any of these frameworks. For example, we released 3.2 in Spring '11. There will be no new features released until 3.3, which is slated to come out in Fall '12 - about 1.5 years. In comparison, the popular Flask framework is about 1.5 years old and has had ~8 point releases, and it can add features whenever it wants at whatever rate it wants. If Armin wants to make a new feature today, he can do that and release it today if he wants. On top of that, web frameworks are like a religion that we would have to choose. There's currently a separation of church and state that has worked well in the community and allowed different frameworks to do different things at different paces. I think we should keep that.
- andybak 15y agoI agree on you regarding a full stack web framework with it's own community such as Django but a lightweight, minimal web framework would be a useful addition to the standard library, surely?
- briancurtin 15y agoSure, it would be great, but whatever we consider would have to be very complete and very mature. There's not much room for evolution in standard library APIs, and with lightweight frameworks being relatively new to the scene, the framework developers themselves probably do not want to give up their current freedom to grow in whatever direction they please. If we look back at this in a few years, maybe it's worth considering as usage grows, APIs are more locked down, and a clear winner shines through. Right now, any inclusion would be months of bike shedding, assuming any of these framework developers are willing to give up external maintenance of their products and go 100% into the standard library.
- rednaught 15y agoAnd end up with something like Perl's CGI? Request/Response favorite flavors seems to change every 2-3 years. I wouldn't want Python to suffer from that bloat.
- sitkack 15y agoPutting something in standard lib effectively kills it. It doesn't mature, it turns into an adult child actor. Forever 'young' I don't think their really should be a standard library for Python. There should be a base, and a much more proactively revved base library, but not a standard library. Part of installing python would be installing the base.
- wisty 15y agoI think the standard library is great. It's good to know that there is a "batteries complete" library that you can really on, that won't change its API for years. Being standard, it's well documented, well vetted, and lots of people know it. There needs to be a wider repo, but pip / easy_install does that OK. What does need to change - there needs to be more "library2" modules. urllib wasn't good enough, so they made "urllib2". Likewise, there's lots of old, outdated modules that could be supplanted.
- reustle 15y agoI've used this quite a bit and love it. My favorite part is that there are no dependencies (that aren't in the standard library).
- heydenberk 15y agoIt seems like being single-file is mostly gimmick. What are the drawbacks to creating a folder with an __init__.py and a handful of readably-long files?
- deleted 15y ago[deleted]
- stevenleeg 15y agoAgreed. The project is ~2700 lines of code all jammed into a single file. Each component is pretty clearly separated from the others with big comment headers, but I don't understand what advantage this has over separate files other than the ability to advertise that it is a single file library.
- Jach 15y agoPerhaps they're not trying to advertise to the Python crowd but to the PHP and JavaScript crowd who might be suckered in by the "Ooh, I only have to include one file?" line.
- dpatru 15y agoJQuery is single file too and that's a big part of it's attraction. Simplicity is a huge plus, not only for users, but also for the developer who is forced to be disciplined. I haven't used bottle yet (just starting), but I'm very impressed with the templating code which seems very powerful and simple. Including the templating system along with the rest of the framework in a single file, forced the developer to think about it more.
- andybak 15y agoBut part of the advantage with jQuery being single-file there is ease of deployment. Python isn't quite as handicapped in this areas as Javascript is. A single line in requirements.txt can add something as complex a complex library to your project without a second thought.
- zyfo 15y agoAnyone who've used web.py and Bottle (for a real project) and care to comment on the pros/cons of both? I'm quite familiar with web.py but not so much with Bottle.
- famousactress 15y agoUsed it early and extensively for a pretty good sized project. In my experience what really happens on a long-lived project is that you end up writing and assembling your own framework on top of the basics that are provided. Not a bad thing if you think you're gonna end up growing a lot of your own infra anyways.. I think mostly I'd use microframeworks like this in the future to do small projects and early prototyping.. or if I thought the project had special needs that was going to make using something like Django a particularly challenging match.
- andybak 15y agoIt's an interesting dynamic. I'm going through a similar thought process except one level of abstraction higher (at the pseudo-CMS level on top of Django). I'm sure similar debates happen at lower levels of abstraction too. You've got to decide for yourself where your 'reinventing the wheel' cutoff point is. For some people it's flipping binary bits, for others, anything lower level than configuring Drupal modules is just a waste of time.
- rmk 15y agoI used this thing in a desktop app that consumed a RESTful API service and received notifications (HTTP POSTs) from the API service. At a high rate, bottle just dies. So if you have a situation where you are making many requests to it, be careful; your mileage may vary.
- grncdr 15y agoWhat WSGI server were you deploying on? I'm thinking of using Bottle for some providing some REST services, so any details you can provide would be helpful.
- gabi38 15y agoHow does it compare with flask?
- lost-theory 15y agoI used bottle for one project, but switched to Flask for everything once it was released. In my opinion the future is very bright for Flask (extensions, blueprints, community). The code and libraries it is built on top of are all extremely high quality.
- StavrosK 15y agoBasically, bottle was here and things were good, and then Armin decided to announce Flask as an April Fools joke and ate poor bottle's lunch. Bottle and Flask are similar enough, but I think Flask has more momentum and support.
- MichaelStubbs 15y agoArmin sums up the differences pretty well in a comment on StackOverflow[1]: "The big difference is that Flask is based on other technologies such as Werkzeug and Jinja2 that exist for a longer time and it does not try to reinvent things. Bottle on the other hand tries to stick to the one-file approach. [...]" [1] http://stackoverflow.com/questions/4941145/python-flask-vs-bottle/4943851#4943851 http://stackoverflow.com/questions/4941145/python-flask-vs-b...
- rednaught 15y agoArmin wrote a post back in January regarding mergers in the Python world of frameworks. http://lucumr.pocoo.org/2011/1/22/python-the-web-and-little-things/#variety http://lucumr.pocoo.org/2011/1/22/python-the-web-and-little-...
- MostAwesomeDude 15y agoI'm not Armin, but I've used both extensively, and the main thing I can feel is that Bottle lacks the elegant power of Flask's underlying libraries. Django suffers from this, too, but in Bottle it's even more obvious: Werkzeug and Jinja2 are deliriously powerful libraries! I remember Armin once talking about how instructional and useful it could be to derive a custom Flask from Werkzeug, and watching his methodology, it became quite apparent that Werkzeug's the best way to do WSGI at the low level. Jinja2's in a similar position; if you've ever read through Django's templating library, you'd agree.
- defroost 15y agoSeems to me to be another micro web framework influenced heavily by Sinatra.
- psykotic 15y agoDo you know enough about the Python ecosystem to make that assessment? Aaron Swartz's web.py was around as a single-file web micro-framework years before Sinatra even existed. An early version of reddit, after they switched from Common Lisp to Python, was built starting with web.py.
- defroost 15y agoI know that web.py was around years before Sinatra. But URL routing in Bottle is more similar to Sinatra than it is to the URL dispatching via a tuple at the top of a file. Even so, perhaps Bottle is influenced more by web.py. That doesn't mean there aren't a ton of ports of Sinatra (like Express for node.js, Scalatra) or those influence by Sinatra like itty (http://toastdriven.com/blog/2009/mar/07/itty-sinatra-inspired-micro-framework/ http://toastdriven.com/blog/2009/mar/07/itty-sinatra-inspire...) or even perhaps Flask. I even noticed a comment above that said Bottle looks just like Itty. Yet because I brought up the Ruby framework that Itty is essentially a port of, I'm getting down-voted like crazy. I will never understand why Python people dislike Ruby so much, and vice versa.
- MostAwesomeDude 15y agoWerkzeug, the library which provides the routes, predates Sinatra by at least a year (2007 compared to 2008 for Sinatra) and might be even older; it predates the SVN->git switch for Pocoo. Python people don't dislike Ruby, they dislike the Ruby community's habit of assuming that Ruby somehow did it first and did it better. :3
- psykotic 15y ago> But URL routing in Bottle is more similar to Sinatra than it is to the URL dispatching via a tuple at the top of a file. Decorators, a Python 2.5 feature, weren't around when web.py was first released, so they couldn't have been used initially. Even after Python 2.5 came out, it took some time for decorators to be widely embraced. But routing and other kinds of dispatching (e.g. adapters and multimethods) are an obvious and indeed commonplace use of them. I didn't down-vote you. I did get ever so slightly annoyed with your implication that Sinatra was the first to do this kind of thing and therefore necessarily a source of influence. Neither half of this claim is correct. Sinatra wasn't the first. Even if it were, it need not have been an influence; I wouldn't claim that web.py had to have influenced Sinatra just because it preceded it.
- puzzler314 15y agoIt looks exactly like Itty (since 2009, updated as recently as 2011): https://github.com/toastdriven/itty https://github.com/toastdriven/itty The only differences I see are minor name changes. I'll have to compare the source code. EDIT: It appears to be an unrelated codebase with a lot of improvements (for example, proper cookie support). Looks like I'll need to be updating my projects.
- OzzyB 15y agoI ♥ Bottle!
- ajray 15y agoThis is exactly what I was looking for. Got up this morning and it was #1 on HN. This is why I <3 HN. Thanks for solving my problems again :-)
- deleted 15y ago[deleted]
- overshard 15y agoExtremely well built and easy to use from a UX (DX? Developer Experience?) perspective. I have recently been using Sinatra and am loving these extremely minimal frameworks. We just need something like Heroku for Python. Gondor maybe?
- brandon 15y agoWell, in fairness, Heroku is now the Heroku for Python. The new Cedar stack (unofficially) supports Python, and some of the frameworks are already being tested on it (http://docs.pylonsproject.org/projects/pyramid_cookbook/dev/deployment/heroku.html http://docs.pylonsproject.org/projects/pyramid_cookbook/dev/...) I managed to get into the betas for both ep.io and gondor, but neither has anything near the polish that the Heroku guys have had years to work on.
- eurohacker 15y agowhat this framework is missing compared to Django
- jarito 15y agoIs it just me or is the first example on their front page a great example of XSS? Unless their standard string formatting routines are performing escaping, this is pretty awful.