Is there a nice and simple interface between Python and MySQL? I've looked at MySQLdb module, SQLAlchemy, and the module provided by MySQL. They work, but are just clunky and difficult to quickly work with. I'm brand new to Python, but I've done this in MATLAB and they have an incredibly easy interface. I.E.
Every time you want to perform a query in Python it seems like you have to do something like:
import datetime
import mysql.connector
cnx = mysql.connector.connect(user='scott', database='employees')
cursor = cnx.cursor()
query = ("SELECT first_name, last_name, hire_date FROM employees "
"WHERE hire_date BETWEEN %s AND %s")
hire_start = datetime.date(1999, 1, 1)
hire_end = datetime.date(1999, 12, 31)
cursor.execute(query, (hire_start, hire_end))
for (first_name, last_name, hire_date) in cursor:
print("{}, {} was hired on {:%d %b %Y}".format(
last_name, first_name, hire_date))
cursor.close()
cnx.close()
Whereas in MATLAB, I initiate the connection once (like when starting up the program, and then retrieving something is as simple as (from here):
[Fn,Ln,Hd] = mysql(['SELECT first_name, last_name, hire_date FROM employees WHERE hire_date = ',num2str(some_date)])
No cursors and connections to make every time you query, just a simple I/O query executer and data returner. I like playing with databases and have many cross-platform projects. Being able to instantly connect to and look at data in MATLAB is an awesome feature. Is there a Python bridge to do this?