Python is great, but why do python frameworks suck that much !?

You are welcome to extract excerpt of this article, but do not copy it entirely on your blog/web site.
You are only allowed to use this post content in an printed article or a newsletter by clearly exposing the source URL of this article.

I love python.
I love it so much that I want to make it my main webdev tool. But why do python web framework are such a pain !?
Why do a missing sqlite initialization cause the whole WSGI system to crumble ?
Just that one took me 3 days (or rather nights) to find out.

I'm used to output XML + XSL in PHP for my templating. It's the best tool for that job I have found until now.
I do like SQL, I find it pretty simple if you know what you want to do and how the data are structured in to your tables.

So, why do we always are stuck with limited templating engines that make the choice of simplicity over functionality?
Why do we inflict ourselves that self-crucifixion that's named ORM ?

I cannot imagine why anyone would go through that.

I mean, I code with optimization in mind. For my Python/PHP code, as for my javascript code, as for my SQL code.
How can any developer being called so if he don't know how to write simple SQL queries?

Now, how would I trust a generic ORM engine to discover the finesse of my database schema, and to do the right outer joins on the right place.
Because I do use outer joins on some tables. And why should I drop the support of my stored procedures ? I do want to use them.
I crafted them with all my love! They deserve to be used.

Ok, so I dwelt into turboGears this week. It's a pretty nice framework, and the fact that it's elements can be deactivated is a big plus (out, SqlObject!).
But now, when I want to do a conditional statement on a class attribute in the templating system (kid, by the way), I find myself incapable of a simple

 
<li class="menuItem">
  <xsl :if test="something_true">
    <xsl :attribute class="menuItem selected"/>
  </xsl>
</li>
 

I've been looking for the last 3 hours how to do a simple switch as that one.
So far, no solutions.

Another thing that grips me is the url mapping...
I use url rewrite in Apache for every projects. I filter the urls so that, for example, http://mysite/info and http://mysite/info/anything/a_person/can?think=of are still mapped to the same PHP file.
Now, how can we do that with turbogears ?

Every url entry point defined have a specific number of parameters. Pass one parameter that is not declared in the entry point and you have an exception.
Any "sub folder" on the url tries to forward the request on another controller.
How am I supposed to manage my site access with that !?

I'm beginning to wonder if I won't stick to PHP.
At least I don't seek for days answers for simple problems with it, I solve them.
Or rather, I will start to consider less "buzz"ier framework, like pylons.
Or maybe port my XML+XSL PHP class to python.

Ok, I do feel better now. Anybody out there with a suggestion on a usable python framework that would not be so much limited ?

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically each day to your feed reader.

Trackbacks & Pingbacks

No trackbacks/pingbacks yet.

Comments

It’s called rails.

I think your problem is the frameworks you’ve looked at. However, if you stick with a WSGI based framework, you should be good.

I personally can’t stand being forced to use a specific ORM solution. In Java, I use Hibernate. In Python, SQLAlchemy. These are what I use regardless of the ’supported’ method. All I care that a web framework does is that it correctly routes an incoming request to the appropriate processing function/class. Anything else they offer, I don’t care about… let me decide how best to do the rest.

What I’m doing for Python is building my own framework based upon WebOb. There is a tutorial here that shows you exactly what you need to know to roll your own framework. Now, you’ll have to choose your own mechanism for DB access, rendering responses, etc… but I prefer to do that myself anyway.

The bonus of this method is that you can still leverage other WSGI components by wrapping your application. For example, it was very easy to add a session handler by wrapping my WSGI app in the beaker session WSGI app.

Also, if you haven’t checked out these frameworks, here’s a list of some others: Django, web.py, web2py, and Pylons.

A ORM tool is a tool that is by design made not to sit in your way like you mention.

Why dont you try django ? Use django and if you dont want the orm tool (i realy dont understand why you wont) you can craft your own DAO/DTO structure.

But for simple tasks like create/insert/update/delete and one to one hydration i think an orm tool really saves the day.

Remember that an orm tool is made for the biggest part of development and not for optimization, specialized queries or else … not that an orm tool cannot be extended to do all of these.

@Dogman: I tried rails, but I don’t like it. I like to have the right to choose how I will do my stuff. I don’t like to be forced to use a specific way to do so.

@marcus: I’m currently reviewing django, and so far, I am pleased with what I see in the documentation section.
Now, I will install it and see how it goes. But on the main points I was ranting here, they are addressed in a rather nice way.

@Iongion: My day job is DBA. I work with stored procedures and design db schema all day long. In the site I’d like to port to python, performance will be a crucial key. For that, I implemented stored procedures into the master DB node that should take care of the most tedious part.
The site I’m talking about is mostly static pages, it’s the service it provides that needs to be optimized, because it might end up with many concurrent requests to the db.
An ORM is great if you want basic insert/update/delete, but when your need is past this, it’s more troubles than help.
And the syntax is terrible.

I did not looked to turbogears as a mean to shorten my development time, but as a tool to abstract myself from tedious bits of web programming.

After doing 8 years of PHP in a professional way (and before my DBA job) I can say that I think I have come to the end of what it can bring me.
As the service is already a python application (called from php with a shell call, urgh…), the portage to a python web site makes totally sense.

Whilst with Rails you can get around the defaults relatively easily, it takes far more research than is reasonable to find out how to do so. So I pretty much reached the same conclusion as you.

What I like about Django is that it exposes the underlying nature of HTTP but provides a lot of convenience methods to allow you to work with it effectively. I’ve found its ORM very useful for the boring bits of data access and when I’m not happy with the number of queries (or complexity) of the SQL being generated I switch to custom queries.

Give web.py a try … it really won’t get in your way.
As for your PHP / XSL combo, I’d be curious to see how you proceed :-)

@tim: I’m browsing the documentation of web.py right now. Thanks for the hint.
As for the PHP+XSL, go to http://www.quixml.org .
I’ve put this together when I was happy enough of the result.

This site itself is build itself with this wrapper, and if you use firefox and you ask to see the source, you will only see the XML.

The wrapper has just a little bit of pre-processing, that allows me to plug in to merge several style sheets into 1.

In simple, I define business logic in classes, and the “public” php pages are composed like that:

< ?php
$objXml->setRendering('html');
$objXml->setXsl('org.quixml.index');
$objXml->start();
   $objXml->general();
   $objXml->open('DATAS');
      $objXml->att('demo','true');
      $objXml->data('feeling','Happy');
   $objXml->close();
$objXml->close();
?>

The xsl style sheets are served from an /xsl/{xsl path} url.
The setRendering() allows me to choose the media type. Standrd html, lo-fi, text, mini (iphone or pda)…
An infinite number of rendering set can be defined, and simply switched with this instruction.

The wrapper handle the client detection. Everything modern enough (Firefox/mozilla, ie 5.5+ and safari 1.3+) receive XML + XSL.
Everything else have the XML transformed locally on the server to be sent as simple HTML4.

Simple and effective…

Thanks for the details. I’m playing with Quixml right now. Liking the idea of client processed views.

If you are interested in using XML and XSLT within WSGI I’d take a close look at Amara. It makes working with XML a breeze. None of the frameworks support XML in a very intimate way, but using Amara, it makes it possible to get the best of both worlds.

I’ve written XSLTemplates, WSGI middleware for templating using XSLT (http://code.google.com/p/xsltemplates). It is going to be integrated into Amara/Akara in the long run, but for now, it is very usable and has been used on production sites. Feel free to contact me with any questions and good luck!

It’s certainly far from perfect, but it do a good job on some toy project I had/have (but like many other, that I have not finished…)

I thought that it could maybe interest other peoples, and created that simple site.
But documentation is awful, I know.

Twitter me (I’m following you now) if something seems not clear enough.

@Eric: THANK YOU !!!!
It’s almost a replica (well, more probably on the other way) of what my PHP xsl wrapper does.

Django looks great, but again, if I can use XML + XSL for the view part, I will be quite happy.

By the way, the link to your blog seems not to be working.
I’ve got a blank page.

I need to change hosts…

But assuming I get things back up and running, I have a mercurial repo with examples of using Amara at http://ionrock.org/hg/

Also, if you want to check out http://xml3k.org there is more information on Amara/4suite related projects.

Thanks a lot for the links Eric. I’m gonna check them tomorrow.
I’ve just quickly read the 4suite project examples page, and I really like it.

The next step I see coming is that I don’t exactly know what is an wsgi compliant application, thus how to implement it.

Turbogears and django seems to handle that themselves, but now I’m too sleepy to understand it.
I simply will do that tomorrow.

You’re using the wrong tools. You dont want and never wanted a framework. For your basic level of programming you just want mod_python

– MV

@MV: maybe I am, well, not using the wrong tool, but at least looking at the wrong one.

But I had similar grip for every framework I ever have looked up, so I’m asking myselfif it’s not my way of working that is simply not adapted to a framework.

And by the way, it’s not because my way of working don’t fit in a framework that it makes it a basic level of programming.
Portability amongst DB is simply not something I want.
Limiting the templating by a reduced set of instruction (and possibilities) is not what I’m looking for.
Creating another blog or wiki engine in python is not what I’m looking for

I have a specific need, for a service who is already running in python, and as the performances of the front end to this service comes in question, a portage of this front-end to Python makes sense.

I don’t want to reduce the functionnalites just to add an “powered by python” at the bottom of the page.

I strongly encourage to look into web2py. The ORM maps one to one into SQL and yet write SQL dialects for you (this makes apps portable, including oracle and the google app engine). You can put anything you want in templates and embed any python code without indentation in {{ }} tags and you do not have the limitations imposed by TG (only “valid” XML) or Django (only “Djangese” in templates). Easy as pie!

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(required)

(required)