Skip to main content

Introduction to Python DB-API for InterSystems IRIS

See the Table of Contents for a detailed listing of the subjects covered in this document.

The InterSystems Python DB-API driver is a fully compliant implementation of the PEP 249 version 2.0Opens in a new tab Python Database API specification.

Note:
DB-API Installation

The InterSystems DB-API driver is implemented as a subclass of the Python Native SDK which must be installed to use DB-API. See Native Python SDK Installation and Setup for details. Once you have installed the Native SDK, no special setup is required to use DB-API. See the code in the following section for an example of how to declare and connect to the DB-API driver.

Usage

The following example makes a connection to the InterSystems IRIS database, creates a cursor associated with the connection, sets up to make some DB-API calls, and then shuts down.

See the Python DB-API Quick Reference for detailed documentation on all implemented DB-API methods and attributes.

Connecting to the DB-API driver and getting a cursor
import iris
import iris.dbapi

def main():
  connection_string = "localhost:1972/USER"
  username = "_system"
  password = "SYS"

  ssl_config = "MyConfig"

  connection = iris.dbapi.connect(connection_string, username, password, sslconfig=ssl_config)
  cursor = connection.cursor()

  try:
    pass  # do something with DB-API calls
  except Exception as ex:
    print(ex)
  finally:
    if cursor:
      cursor.close()
    if connection:
      connection.close()

if __name__ == "__main__":
  main()

See iris.dbapi.connect(), Connection.close(), Connection.cursor(), and Cursor.close() for more information on the methods called in this example. See TLS with Python Clients for information on setting up secure connections.

FeedbackOpens in a new tab