MS Access library for python [duplicate] MS Access library for python [duplicate] python python

MS Access library for python [duplicate]


Depending on what you want to do, pyodbc might be what you are looking for.

import pyodbcdef 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 odbcdef 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).


You can use pypyodbc to easily create an empty Access MDB file on win32 platform, and also compact existing Access MDB files.

It can be as easy as:

import pypyodbcpypyodbc.win_create_mdb( "D:\\Your_MDB_file_path.mdb" )

More over, as an dbi 2.0 ODBC library, pypyodbc is highly compatible with pyodbc, you can do SQL database queries like SELECT, INSERT, UPDATE with the library.

Here is the full Tutorial about pypyodbc's Access support.

Disclaimer: I'm the developer of pypyodbc.