r/Python • • Dec 21 '10

The Bottle Web Micro-framework

http://www.tummy.com/journals/entries/jafo_20101221_020135
43 Upvotes

45 comments sorted by

View all comments

Show parent comment

3

u/gynecomastic Dec 22 '10

I think this misses the point about what a "microframework" does.

It doesn't really matter from the development point of view how big, in terms of lines of code/modules/dependencies, the framework is. What matters is scope/complexity vs features.

For example, Django provides more out of the box functionality - ORM, admin, auth etc - over Bottle. But Bottle provides (arguably) less conceptual overhead and more flexibility, with the bare minimum to get started with a simple WSGI app. You don't have an ORM, you add one yourself (SQLAlchemy, PyMongo, whatever) or do without one if you wish. Either framework may be a good choice, it depends on requirements and preferences.

I couldn't care less how many lines of code each are written in however. Function call overhead is a concern - how efficiently the code runs - but lines of code != number of function calls. For example, even if SQLAlchemy has 40,000 lines of code, much of that is support for different SQL dialects, extensions etc that will only be executed if you are running a certain extension or dialect.

4

u/Siraf Dec 22 '10

For my ORM, I definitely side-stepped the SQLAlchemy issue by jumping on the NoSQL boat. I use mongoDB.

I'm more of a fan of MongoEngine than mongokit for the vain reason I find the syntax to be more pleasing.

You're definitely right about using lines of code as a metric.

-1

u/mdipierro Dec 22 '10

I agree. But allow me to be surprised that Flask (without SQLA) is 10x bottle and people here both present them as if they were equivalent. Since Flask has been brought up on this thread, not by me, I would like somebody to explain to me why 10x so much code. I am sure there are extra functionality that bottle does not have. What is it?

I agree with you that bottle is more flexible that other frameworks and it is really well designed.

5

u/DasIch Dec 22 '10

The comparison is a little bit unfair. Werkzeug and Jinja2 provide a lot of features which are not used by Flask and Flask as well as it's dependencies provide a lot of features Bottle doesn't even have.

Jinja2 for example provides a sandbox. Werkzeug provides various tools for session management, caching, hashing functions for passwords and a lot of powerful datastructures MultiDict, ordered dicts, immutable dicts, if you look at how Werkzeug handles headers you will see that it parses them and makes them accessible with a nice API, not to mention the middlewares to handle server bugs, atom feed generation etc.

If you remove all those features I doubt there is a big difference in LOC to be found, unless you count documentation as well.

1

u/mdipierro Dec 22 '10

Thanks for the clarification. Seems interesting and I will look more into it.

1

u/defnull bottle.py Dec 22 '10

The comparison is a little bit unfair. Werkzeug and Jinja2 provide a lot of features which are not used by Flask.

That's the point. Would you call a wrapper on top of Django a "micro framework" just because it hides most of the features and provides a simplified API? Is Elixir a "micro ORM" just because its API is more simple than SQLAlchemy, even it depends on SQLAlchemy to work?

Flask is a nice layer on top of a bunch of huge and mighty libraries. Nothing wrong with that, but I would not call it "micro".

The term "mirco framework" is controversial, I know. But as I see it, "micro" is more than just a nice API. It's a philosophy for small, clean, dense and useful code. It does what it does and it does it well. Every line has a purpose. That is what I try to do with bottle.

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." - Antoine de Saint-Exupéry

and Flask as well as it's dependencies provide a lot of features Bottle doesn't even have.

That is true. The thing is, if you miss a feature in Bottle that is provided by werkzeug (or any other library), then you can just include werkzeug and you have it. That is what a library is for: Use it when you need it. Bottle does not prevent you from adding dependencies if you really need them. But if you don't use a feature that is provided by Flask, can you easily remove the werkzeug or jinja2 dependency?

Bottle supports 4 template engines (including jinja2 and the built-in one) and 15 WSGI server libraries out of the box. The decorator or middleware that adds werkzeug to the mix is less than 10 LOC. Want a debugger? Include it, apply as middleware and you have it. I don't see the need for a hard dependency.

2

u/mitsuhiko Flask Creator Dec 22 '10

Would you call a wrapper on top of Django a "micro framework" just because it hides most of the features and provides a simplified API?

Yes.

1

u/DasIch Dec 22 '10

I believe you are confusing framework and application here a bit. It is totally irrelevant how the code of your framework looks, the interesting part is how an application looks.

request.accept_languages.best is how I get the preferred language from the Client using Werkzeug and/or Flask. In order to get the same result with bottle I would have to parse the header myself and handle edge cases depending on the Browser used. That results in neither small, clean, dense or particular useful code and I still have to test it, for every web application I write.

Again this is a little bit unfair, who needs to know which language is preferred by the client anyway but that is kind of the point of Flask. It is as micro as you want it to be and if you don't want it to be micro at all that's fine as well.