Skip to main content

Deciding How to Use InterSystems IRIS with Python

So far, you have been only working with InterSystems IRIS® data platform through the traditional client-server architecture with the DB-API driver. While this offers familiarity and simplicity for Python developers, it limits access to many of the advanced, high-performance features that separates InterSystems IRIS from other databases.

Luckily, InterSystems IRIS offers flexible and powerful ways to integrate Python into your data workflows, either within the kernel (Embedded Python), or via external connections (APIs, gateways, and SDKs). This document guides you how to go beyond the traditional access methods and unlock the full potential of InterSystems IRIS by integrating Python more deeply. By using Embedded Python alongside ObjectScriptOpens in a new tab—InterSystem’s native procedural programming language—you can enhance your application design, performance, and scalability.

Using Python across the InterSystems IRIS Platform

Not every application is the same. Each application requires features and capabilities specific to its needs. InterSystems IRIS offers many options in the ways you can implement your applications with Python depending on what you are looking for.

There are five ways to use Python with InterSystems IRIS. They are:

  1. DB-API: Implements a PEP 249–compliant direct interface with InterSystems databases through the DB-API driver.

  2. pyODBC: Establishes an Open Database Connectivity (ODBC) connection to InterSystems IRIS through the ODBC driver.

  3. IRIS Native: Provides direct access to many InterSystems IRIS features from Python through the Native driver.

  4. Python Gateway: Provides direct access to many InterSystems IRIS features through a gateway.

  5. Embedded Python: Runs Python inside the InterSystems IRIS kernel.

All of the Python Support with InterSystems IRIS
Embedded Python differientiates itself from other Python run methods in that it runs alongside the InterSystems IRIS process
Note:

Running Embedded Python via the irispython interpreter does not actually run your Python script inside the InterSystems IRIS kernel. Look into Embedded Python to see the full details.

DB-API

The InterSystems IRIS Python DB-API driver provides a standards-compliant interface for accessing InterSystems IRIS data from external Python applications. It is based on the widely adopted Python DB-API 2.0 (PEP 249), making it easy for developers to work with InterSystems IRIS using familiar Python database interaction patterns.

This driver comes bundled as part of the Native API and is distributed via a single Python package (through a wheel). It enables client-side access to InterSystems IRIS, connecting over the network to interact with data in a relational, SQL-like way.

When to Use the DB-API Driver

  • You are developing external Python applications (for example, data processing, analytics, or web services) that need to connect to InterSystems IRIS over a standard interface.

  • You prefer or require working entirely with Python, outside of the InterSystems IRIS environment.

  • You want to leverage the standard Python database workflow, including connection objects, cursors, and SQL execution.

  • You are integrating InterSystems IRIS with Python tools and frameworks that expect DB-API compatibility (for example, pandas, SQLAlchemy, ORMs, Flask, and Streamlit).

pyODBC

pyODBC is a Python module that provides a bridge between Python and databases via the ODBC standard. It implements the Python DB-API 2.0 specification and allows applications to connect to InterSystems IRIS using ODBC drivers.

Important:

While it offers broad compatibility and has historically been used in many Python database workflows, pyODBC is no longer the recommended approach for connecting to InterSystems IRIS in most cases. Instead, use the DB-API driver.

When to Use pyODBC

  • You need to connect to older versions of InterSystems IRIS (prior to version 2022.1) that do not support the Python DB-API driver.

  • You are working in an environment where ODBC is already in place and integration depends on existing Data Source Names (DSNs).

  • Your workflow depends on a low-level, ODBC-based architecture, such as certain legacy reporting or business intelligence tools that are being accessed from Python.

IRIS Native

The InterSystems IRIS native API allows Python applications to interact directly with InterSystems IRIS through low-level access to its core data structures—specifically, globalsOpens in a new tab, the high-performance, multi-dimensional arrays used internally by InterSystems IRIS.

This API is part of the Native SDK and enables external Python code to connect to InterSystems IRIS over the network and perform non-relational operations without using SQL. It offers fine-grained control over data and is well-suited for advanced or performance-critical applications.

When to Use the Native API

  • You need direct access to InterSystems IRIS globals, bypassing SQL and object layers.

  • You are building high-performance or low-latency data processing systems that benefit from schema-less access.

  • You are developing Python applications that run outside of the InterSystems IRIS environment.

  • Your use case involves non-relational data models, such as hierarchical structures or key-value stores.

Python Gateway

The Python Gateway, also known as the External Language Server, enables InterSystems IRIS to call out to Python code running externally, reversing the usual client-server relationship. Instead of Python initiating the connection to InterSystems IRIS, InterSystems IRIS becomes the caller, invoking Python code that resides on a separate system or process. This method establishes a communication bridge from InterSystems IRIS to Python, making it possible to integrate Python logic—such as a machine learning models, data processing routines, or specialized computations—into InterSystems IRIS workflows.

The gateway runs as a separate service and communicates with InterSystems IRIS over a defined protocol, allowing Python to be part of business logic, orchestration, and process automation within the InterSystems IRIS environment.

When to Use the Python Gateway

  • You want InterSystems IRIS to initiate execution of external Python code that lives outside the database processes.

  • You are integrating existing Python applications, scripts, or services into InterSystems IRIS business logic.

  • Embedded Python is not available in your deployment, but Python functionality is still required.

  • Your use case involves external systems or APIs that are best handled by Python but must be coordinated from within InterSystems IRIS.

  • You want to build or extend interoperability productions using Python components.

PEX Framework: A Key Use Case for the Python Gateway

The Production EXtension (PEX) frameworkOpens in a new tab is an important example of how the Python Gateway architecture is used in practice. PEX allows you to develop interoperability productions—InterSystems IRIS workflows that integrate systems with different message formats and protocols—using external languages such as Python. With PEX, you can implement business services, processes, and adapters in Python that run as separate services connected via the gateway. These Python components are invoked at runtime and communicate with other production elements through the PEX messaging system, enabling seamless integration with InterSystems IRIS interoperability productions.

Moving Beyond the DB-API Driver

In the client-server setup, Python and InterSystems IRIS run in separate processes. This means that each request between them must travel across a network boundary. These requests introduce latency, require serialization, and prevent tight integration with InterSystems IRIS-specific features. To fully benefit from InterSystems IRIS’s capabilities, consider running Python within the same process as the database. This is where Embedded Python comes in.

Embedded Python: Running Python alongside InterSystems IRIS

Python can be embedded directly into InterSystems IRIS processes. Running Python and InterSystems IRIS in the same process introduces many benefits that the traditional client-server model does not have.

The benefits of Embedded Python are:

  • Performance: There is no need to serialize data between InterSystems IRIS and Python.

  • Simplicity: Seamlessly integrate Python with InterSystems IRIS.

  • Security: There is no need to open any additional ports for communication between InterSystems IRIS and Python. You can leverage the InterSystems native security model.

  • Scalability: Utilize InterSystems IRIS’s ECPOpens in a new tab and shardingOpens in a new tab features to easily scale your applications.

This seamless integration of Python with InterSystems IRIS also allows you to access the distinguishing features of InterSystems IRIS, such as interoperability and high-performance multi-model databases.

Running Embedded Python

There are three ways to run Embedded Python. However, the most “Pythonic” way to work with Embedded Python in InterSystems IRIS is through the irispython command. By running irispython myscript.py in the command line, you use the irispython interpreter to run your Python scripts in-process, connected to InterSystems IRIS. This practice is the best for clear code separation. The irispython interpreter is a built-in Python interpreter that interacts with InterSystems IRIS data. Though it provides the same capabilities and interface as the two other ways to run Embedded Python, the irispython interpreter is not truly “embedded” as it still runs Python and InterSystems IRIS in separate processes. To completely bridge the gap between your code and InterSystems IRIS, consider learning ObjectScript to utilize the other two ways to run Embedded Python.

Embedded Python is the recommended way to integrate Python tightly with InterSystems IRIS. It delivers the speed, simplicity, and power you need to build modern, scalable applications, while still giving you access to the full feature set of InterSystems IRIS, including ObjectScriptOpens in a new tab, and advanced data management tools.

Python Processes with InterSystems IRIS
Embedded Python differientiates itself from other Python run methods in that it runs alongside the InterSystems IRIS process
Note:

ObjectScript is the native InterSystems programming language, which you can combine with Python if needed. It is not required to get started with irispython. However, some of InterSystems IRIS’s unique capabilities come from ObjectScript’s architecture designed specifically for powerful and flexible data models. To fully utilize InterSystems IRIS, consider learning ObjectScript to compliment it to your applications.

If you are ready to move beyond traditional Python database access and fully embrace what InterSystems IRIS has to offer, Embedded PythonOpens in a new tab is the path forward.

Choosing the Right Path for You

It is important to choose the right Python method when working with InterSystems IRIS to fully take advantage of each approach. Understanding the nuances of each option can help determine which path to take. Use the following as resources to help navigate the broad Python support system that InterSystems IRIS provides.

Python Support Capabilities

Use Case DB-API/pyODBC Native API Python Gateway Embedded Python
Client Applications X X    
SQL Stored Procedures, Functions, Triggers     (Possible) X
Augmenting existing InterSystems IRIS Classes       X
Interoperability     X (PEX) (Possible)
Manipulating Globals   X X X

Python Uses Cheat Sheet

What you are Building Recommended Python Method Why this Works Well
REST APIs, dashboards, client applications, or relational database access requiring SQL calls (for small amounts of data) DB-API or pyODBC Familiar SQL-based access; great for lightweight, structured data interactions
Applications needing direct access to InterSystems IRIS globals or non-relational data Native API Offers low-level access to hierarchical and multi-dimensional data structures
InterSystems IRIS logic that needs to call external Python code Python Gateway (PEX) Allows InterSystems IRIS to trigger Python scripts or models externally; great for interoperability productions
High-performance, data-intensive logic close to the database Embedded Python Runs inside the InterSystems IRIS kernel; lowest latency and tightest integration with the data
FeedbackOpens in a new tab