[Twisted-Python] recommended twisted database coding

Hi everyone, As of late I've been thinking of rewriting an old PHP application that I used to help out on in Python. It would give me a chance to see if Python and everything I"ve learned while learning Python would help me overcome my innate disgust of doing database/web programming :) The application in question is relatively simple - it's your average "manage-all-my-music" application, with artists, audio files, albums, ratings, ... In the PHP version, I had already moved from doing raw SQL queries everywhere to instantiating objects from the database, so the idea of having an object model that abstracts away persistence to a database is appealing. Being a Twisted groupie I would prefer to use something that works well with Twisted. After looking at all the options available to me, I'm getting a little confused, and would like some feedback to clear up the confusion. - Twisted is, of course, async, so twisted.enterprise.adbapi wraps 2.0 DB API's using threads, which makes sense. Are people using adbapi much in production though ? From scanning the mailing list it seems like people prefer layering stuff on top of adbapi to implement object models. - Axiom seems like a nice Object layer with a database backend. However, the part I don't understand is that suddenly the description claims that Axiom is doing blocking SQLite calls, and that this isn't really a problem. Since Axiom is a Divmod project, I tend to trust their opinion when it comes to Twisted. But why is it suddenly OK to have blocking code being used ? Does this only apply to SQLite, or would it apply to any database being used ? - SQLObject seems to come very close to what I would want to use to abstract away the database backend, and just pretend that I only deal with persistently stored python objects. Has anyone managed to use SQLObject in a twisted project ? If not, what's the closest I can get that gives me the advantage of having a python object backend ? - how do persistent object systems typically deal with transactions ? Suppose you want to do three operations on three different objects as a transaction, is that possible at all ? - Are there any active projects that use a database backend, twisted, persistent objects, and are freely available, that I can sneak a peek at for my further education ? Thanks in advance, Thomas

* Thomas Vander Stichele <thomas@apestaart.org> [2006-06-08 12:05:22 +0200]:
One thing that's "special" about SQLite is that in runs in-process, so there are no network latency issues involved; like any other "blocking" code, the idea is to only do small bits of work at a time. If you need to run long queries, you would either break them up into smaller chunks, or run them in a separate process/thread/whatever to avoid blocking the main server.
I'm only really familiar with Axiom, so I can't comment on SQLObject and friends; in Axiom, the Store (which is the application-level object you use to interact with the database) has a transact() method which you invoke like store.transact(someFunc, arg1, arg2, ...). Within the transaction, any object manipulations/queries/etc. you perform obviously turn into SQL queries in the database layer, and these are run in an SQL transaction. -- mithrandi, i Ainil en-Balandor, a faer Ambar

On Thu, 08 Jun 2006 12:05:22 +0200, Thomas Vander Stichele <thomas@apestaart.org> wrote:
Hi everyone,
Axiom was designed from the ground up as a Twisted-friendly database. You can store Twisted service objects in axiom databases, and run axiom databases as twisted servers using the 'axiomatic start' command. If you're writing a blog/cms type thing, you should probably look at this brief tutorial for an example of how such things get built with axiom: http://divmod.org/trac/wiki/MantissaBlogTutorial (mantissa is axiom+nevow+athena+glue, basically) Other database integration tools may be more database-y (and, for example, give you a choice of database backend, which axiom does not currently do) but you are unlikely to find one twistier than axiom ;).

Quoting Thomas Vander Stichele <thomas@apestaart.org>:
Hi everyone,
Hi,
Here we use adbapi a lot, against Postgresql, MySQL and SQLite. Note that adapi is mainly a wrapper around a threadpool, there's very little magic in it (which explains it works great).
We did that too :). I just modeled a simple ORM to construct objects from SQL results (it just put the values into attributes of a dict or an object). We also use a simple wrapper around ConnectionPool to handle specific databases problems (concurrent updates in Postgres or timeouts in MySQL), and add other methods (for example executemany of pysqlite2 is very useful).
I strongly discourage you from using SQLObject. It's really a pain to use, and there's implicit behaviours that are nasty (cache, attributes retrieval...). It's not very hard to use with a thread pool in Twisted, but I think it's really designed for simple threaded (web) apps. SQLAlchemy seems much cleaner (but still in early stage) and as advised by Ed Suominen you should take a look at sAsync. -- Thomas ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Thomas Vander Stichele wrote:
I recomend you "durus" (http://www.mems-exchange.org/software/durus/) and, depending of your usage profile, my storage backend: <http://www.argo.es/~jcea/programacion/durus-berkeleydbstorage.htm> Yes, durus supports transactions. Durus is not async, but wrapping it in a thread should be easy enough. I'm fairly involved with Durus, so I could help you there. - -- Jesus Cea Avion _/_/ _/_/_/ _/_/_/ jcea@argo.es http://www.argo.es/~jcea/ _/_/ _/_/ _/_/ _/_/ _/_/ jabber / xmpp:jcea@jabber.org _/_/ _/_/ _/_/_/_/_/ _/_/ _/_/ _/_/ _/_/ _/_/ "Things are not so easy" _/_/ _/_/ _/_/ _/_/ _/_/ _/_/ "My name is Dump, Core Dump" _/_/_/ _/_/_/ _/_/ _/_/ "El amor es poner tu felicidad en la felicidad de otro" - Leibniz -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iQCVAwUBRI7CGZlgi5GaxT1NAQJHKQQAl+ZB5zjX+n51dandH3q7n1M20qnoEdbI mkIZ0rKX8BFKcCixp9ZlJf01HszNJ93OqUxlNofwZKRz26JoO+FGjtZrV9QYDWUC /uOdSinqsrpCgRhYOOnNjut/ks/RpHVsknHPWfxQL9nUDHqLObvy8PmGvhVkl9wk u6CPJzETaec= =yaBs -----END PGP SIGNATURE-----

* Thomas Vander Stichele <thomas@apestaart.org> [2006-06-08 12:05:22 +0200]:
One thing that's "special" about SQLite is that in runs in-process, so there are no network latency issues involved; like any other "blocking" code, the idea is to only do small bits of work at a time. If you need to run long queries, you would either break them up into smaller chunks, or run them in a separate process/thread/whatever to avoid blocking the main server.
I'm only really familiar with Axiom, so I can't comment on SQLObject and friends; in Axiom, the Store (which is the application-level object you use to interact with the database) has a transact() method which you invoke like store.transact(someFunc, arg1, arg2, ...). Within the transaction, any object manipulations/queries/etc. you perform obviously turn into SQL queries in the database layer, and these are run in an SQL transaction. -- mithrandi, i Ainil en-Balandor, a faer Ambar

On Thu, 08 Jun 2006 12:05:22 +0200, Thomas Vander Stichele <thomas@apestaart.org> wrote:
Hi everyone,
Axiom was designed from the ground up as a Twisted-friendly database. You can store Twisted service objects in axiom databases, and run axiom databases as twisted servers using the 'axiomatic start' command. If you're writing a blog/cms type thing, you should probably look at this brief tutorial for an example of how such things get built with axiom: http://divmod.org/trac/wiki/MantissaBlogTutorial (mantissa is axiom+nevow+athena+glue, basically) Other database integration tools may be more database-y (and, for example, give you a choice of database backend, which axiom does not currently do) but you are unlikely to find one twistier than axiom ;).

Quoting Thomas Vander Stichele <thomas@apestaart.org>:
Hi everyone,
Hi,
Here we use adbapi a lot, against Postgresql, MySQL and SQLite. Note that adapi is mainly a wrapper around a threadpool, there's very little magic in it (which explains it works great).
We did that too :). I just modeled a simple ORM to construct objects from SQL results (it just put the values into attributes of a dict or an object). We also use a simple wrapper around ConnectionPool to handle specific databases problems (concurrent updates in Postgres or timeouts in MySQL), and add other methods (for example executemany of pysqlite2 is very useful).
I strongly discourage you from using SQLObject. It's really a pain to use, and there's implicit behaviours that are nasty (cache, attributes retrieval...). It's not very hard to use with a thread pool in Twisted, but I think it's really designed for simple threaded (web) apps. SQLAlchemy seems much cleaner (but still in early stage) and as advised by Ed Suominen you should take a look at sAsync. -- Thomas ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Thomas Vander Stichele wrote:
I recomend you "durus" (http://www.mems-exchange.org/software/durus/) and, depending of your usage profile, my storage backend: <http://www.argo.es/~jcea/programacion/durus-berkeleydbstorage.htm> Yes, durus supports transactions. Durus is not async, but wrapping it in a thread should be easy enough. I'm fairly involved with Durus, so I could help you there. - -- Jesus Cea Avion _/_/ _/_/_/ _/_/_/ jcea@argo.es http://www.argo.es/~jcea/ _/_/ _/_/ _/_/ _/_/ _/_/ jabber / xmpp:jcea@jabber.org _/_/ _/_/ _/_/_/_/_/ _/_/ _/_/ _/_/ _/_/ _/_/ "Things are not so easy" _/_/ _/_/ _/_/ _/_/ _/_/ _/_/ "My name is Dump, Core Dump" _/_/_/ _/_/_/ _/_/ _/_/ "El amor es poner tu felicidad en la felicidad de otro" - Leibniz -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iQCVAwUBRI7CGZlgi5GaxT1NAQJHKQQAl+ZB5zjX+n51dandH3q7n1M20qnoEdbI mkIZ0rKX8BFKcCixp9ZlJf01HszNJ93OqUxlNofwZKRz26JoO+FGjtZrV9QYDWUC /uOdSinqsrpCgRhYOOnNjut/ks/RpHVsknHPWfxQL9nUDHqLObvy8PmGvhVkl9wk u6CPJzETaec= =yaBs -----END PGP SIGNATURE-----
participants (5)
-
glyph@divmod.com
-
Jesus Cea
-
Thomas HERVE
-
Thomas Vander Stichele
-
Tristan Seligmann