views:

694

answers:

8

Is there a module written purely in Python that will allow a script to communicate with a MySQL database? I've already tried MySQLdb without success. It requires too much: GCC, zlib, and openssl. I do not have access to these tools; even if I did, I don't want to waste time getting them to work together. I'm looking for tools that will make my work easier.

Can someone point me in the direction of a MySQL Python module written in Python? If not, tips on writing my own code for communicating with MySQL would be appreciated.

Thanks,

Tony

+1  A: 

Without a doubt MySQLdb is the best solution, but if you can't use it…

If you have libmysqlclient.[so|dll], you could access it directly using ctypes module.

vartec
A: 

As far as I know there is no direct alternative. The only thing I can think of is to use ODBC instead, via pyodbc. The MySQL site has an ODBC connector you can download. But I've never used this approach myself, so I can't say how well it will work.

DNS
+3  A: 

You can find pre-built binary packages for MySQLdb and its dependencies for most operating systems.

http://sourceforge.net/project/showfiles.php?group_id=22307&package_id=15775

What platform are you running on?

Chris AtLee
The pre-built binary packages are out of date. They don't offer a Python 2.6 version or x64 packages for windows.
Varin
The platform is a HostGator account on a shared server. MySQL and Python 2.4 are built-in, but I don't have access to GCC, among other things.Since the database is small, I'm thinking that perhaps SQLite is the way to go. I hear it's very easy to install and use.
Tony
Python 2.6 includes support for SQLite so that might be a good direction to go.
envalid
The OP has said he's stuck on python 2.4 so prebuilt binaries should be fine.
jcdyer
+1  A: 

You've looked at these?

http://wiki.python.org/moin/MySQL

Adam Nelson
+3  A: 

There's a project at Sun to implement 100% python mysql driver.

https://launchpad.net/myconnpy

I haven't found any code for it though. But according to a blog comment, it's more than vaporware.

piquadrat
+1  A: 

Thanks everyone for your answers. Since I'm working with a small database (a few hundred records, mainly names and addresses) I've decided to use SQLite. I just discovered it. It seems to be perfectly suited for my purposes; it was simple to install (took about two minutes) and works well with Python. I'm stuck with Python 2.4 so I can't use the sqlite3 module, but I'm able to communicate with the database by using Python's 'subprocess.Popen' function and command-line parameters.

Tony
There's a Python 2.4 SQLite module -- use that -- it's much better then fooling around with subprocess.Popen. http://oss.itsystementwicklung.de/trac/pysqlite
S.Lott
Thanks! I'll check it out.
Tony
+4  A: 

Lately there is also oursql (docs), which has various advantages over MySQLdb and other existing drivers -- listed at the top of the documentation.

Brendon
The first "advantage" they list is fud. "Real Parameterization?" MySQLdb has that already.
jcdyer
@jcd: I believe that MySQLdb has no real parameterization. Check this: lists.mysql.com/internals/34723
eugene y
A: 

As mentioned in earlier answer, MySQL Connector/Python implements the MySQL Server/Client completely in Python. No compiling, just installing.

Here are the links:
* https://launchpad.net/myconnpy
* code: https://code.launchpad.net/myconnpy
* download: https://launchpad.net/myconnpy/+download (development shapshots)

It's not complete yet, but it should have enough to keep you going. (FYI, I am the maintainer)

geertjanvdk