Python, Firefox programming and Irish Whiskey.

Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Thursday, September 2, 2010

SQLAlchemy Custom Types

SQLAlchemy is just ingenious. I must admit I haven't worked with any other ORM before, yet SQLAlchemy is more than that. I have been working with it's query language for years (4-5) and just recently I started to tuck into orm. So easy to use and so comprehensive.

If you want to do something related to your database, with SQLAlchemy you probably can. I, for example, need to "modify" a date-time value read from Oracle database backing our ERP. I suspect somebody didn't bother to set-up the timezone information properly. So all I had to do was to subclass types.TypeDecorator and override member function process_result_value to do some magic about my datetime values. That was it (I only read the data so I didn't care about converting back.)

Monday, July 12, 2010

pylons, sqlalchemy, pickles

My blog has got Python in the title and yet there hasn't been a serious Python related post. You might have guessed I use Pylons because I tried to run Pylons under Google App Engine. I abandoned these efforts ever since and decided to use the setup I am used to for my next projects. Currently I use quite traditional:

  • python 2.5 or 2.6
  • pylons, currently 0.9.7 because I started with version 0.9.3 or 0.9.4 and it would be to much work to get rid of webhelpers.rails
  • sqlalchemy 0.5 (with MySQL)
  • authkit
  • formencode
  • prototype, because it used to be a part of webhelpers
  • simile timeline, flotr and a bunch of other javascript tools
  • reportlab for pdf generation

For new projects I will move on to:

  • pylons 1.0
  • sqlalchemy 0.6 even though it is not officially supported in pylons
  • not sure about an auth... middleware, perhaps repoze, perhaps something else
  • not sure about formencode but probably yes
  • jquery

I am experimenting with some pickling and unpickling. In one project I am saving pickled data directly into the database. Of course I don't expect I will be able to use the pickled data as database keys or even search in them. The keys will stay in their own native sql colunms. The pickled section will just have some additional info in it. Using sqlalchemy this is rather easy to do. I defined my model declaratively like this>: And for working with unpickled details: You cannot do: If you look at the declaration, you will probably realize why.

In another project I just pickle an object and send it to a client through network. There I unpickle it and use it. Strange things were hapenning. When I have both the server and the client on the same maching it worked perfectly. But when I moved the server elsewhere, it stopped working. It took me a few hours before I realized that on the server I had old version of the module containing the class for the pickled object, which was an old-style class. Of course the unpickling didn't work then.

Wednesday, April 28, 2010

pylons in appengine

Hello again, after more than a month. Sorry you had to wait. So I have got pylons in google appengine up and running. Haven't done anything yet, just an "empty" application. Anyway, I had to compile my own python, as OpenSUSE 11.2 already contains version 2.6 and doesn't seem to have 2.5 packages in my current set of repositories. After I compiled python for the first time (./configure ; make ; sudo make install) and run python2.5, I saw that I could not use commandline properly, so I installed readline-devel. Then I compiled again, tried a bit of the appengine-monkey guide, found out that something wasn't compiled in, installed another devel package and went again. The packages I had to install were:
  • readline-devel
  • zlib-devel
  • openssl-devel
  • sqlite3-devel
Then I successfully run the bloody thing. After some mistake on my side I decided to go for Pylons-0.9.7 instead of the fresh 1.0-prerelease and I installed an older webob as one of the comments on appengine-monkey wiki advices. That's about it for now. I will keep you posted with updates.