How do I get started?

+8  A: 

cx_Oracle is a Python extension module that allows access to Oracle databases and conforms to the Python database API specification.

More information is available here. Here is a sample showing how to connect and process a query.


import cx_Oracle
conn = cx_Oracle.connect(connstr)
curs = conn.cursor()

curs.execute('select * from emp')
print curs.description
for row in curs:
    print row
Mark Harrison
+3  A: 

Extra information:

  • The complete connstr for a non-local database should could be something like 'scott/[email protected]_SID'
  • You'll the oracle client installed (Instant Client might be a good choice) and your tnsnames.ora configured
+4  A: 

Also, you can bypass TNS by using this as a connection string: scott/[email protected]:1521/DATABASE_SID

+3  A: 

The Oracle Technology Network website has a lot of Python examples that would be worth reviewing.

Querying best practices:

Data Parsing:

Working with Times and Dates:

David Aldridge
+2  A: 

I just set up cx_Oracle on windows. It was very tricky. Ultimately I needed to tweak my path variable: I needed to set ORACLE_HOME and ORACLE_BASE to C:\oracle\ora9 and C:\oracle respectively.

Also, I first downloaded cx_Oracle for Oracle 10 because I new that was the DB. But we use Oracle 9 libraries. I had to reinstall the right cx_Oracle version.

If "SQL Plus" does not work, you have environment issues to sort out.

cx_Oracle does work with Oracle's instantclient, which does not by default include SQL*Plus - so for testing purposes an additional install may be required to get SQL*Plus.
Jeffrey Kemp