Is there a library for using MS Access database in python? The win32 module is not as easy as the MySQL library. Is there a simpler way to use MS Access with Python?
TL;DR – You need 32-bit Python for 32-bit Access, or 64-bit Python for 64-bit Access. One thing to note upfront, if you have 64-bit MS Access, you'll want to use the 64-bit Python for this exercise. Mixing up a 64-bit Python with 32-bit Access will throw an error when you try to connect.
PostgreSQL database PostgreSQL is the recommended relational database for working with Python web applications.
Depending on what you want to do, pyodbc might be what you are looking for.
import pyodbc def mdb_connect(db_file, user='admin', password = '', old_driver=False): driver_ver = '*.mdb' if not old_driver: driver_ver += ', *.accdb' odbc_conn_str = ('DRIVER={Microsoft Access Driver (%s)}' ';DBQ=%s;UID=%s;PWD=%s' % (driver_ver, db_file, user, password)) return pyodbc.connect(odbc_conn_str) conn = mdb_connect(r'''C:\x.mdb''') # only absolute paths!
Note: you may download the freely-redistributable new-driver, if you don't have MSOffice installed.
I don't think win32 is hard. Try use its odbc module. Example of code working with ODBC and PostgreSQL database:
import odbc def get_pg_ver(db_alias): connection = odbc.odbc(db_alias) try: cursor = connection.cursor() cursor.execute('SELECT version()') for row in cursor.fetchall(): print row[0] finally: connection.close() get_pg_ver('odbc_name/user/passwd')
This is very similar for every db driver I used in Python and Jython (I work with PostgreSQL, Oracle and Informix).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With