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 via external connections (APIs, gateways, and SDKs) or within the kernel (Embedded Python). This document guides you how to go beyond DB-API and unlock the full potential of InterSystems IRIS.

Python Options

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. This document summarizes the ways of using Python with InterSystems IRIS and highlights some of the use cases for each of them.

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

Client-Server Options

The four client-server options use language SDKs that run Python outside of the InterSystems IRIS process.

  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. Native API: Provides direct access to many InterSystems IRIS features from Python through the Native driver.

  4. Python Gateway: Calls out to an external language server.

Embedded Python

With Embedded Python, Python runs in the same process as InterSystems IRIS. Embedded Python provides the lowest latency out of all these options.

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 SDK 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.

Note:

If you are using DB-API and the client is on same machine as InterSystems IRIS, Python and InterSystems IRIS communicate using shared memory by default, for greater performance. This option can be turned off if you need Python to communicate with InterSystems IRIS using a secure connection, or to simulate connecting from another machine via TCP/IP. See Creating a Connection Object for details.

Note:

DB-API and Embedded Python both require you to import an iris module. Though the modules have some methods with similar names, they have separate APIs and are not interchangeable. DB-API uses the connect() method of the Native SDK’s iris module to create a connection object. For information, see Using the Python DB-API.

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).

For more information, see Using the Python DB-API.

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.

For more information, see ODBC Support for Python and Node.js.

Native API

The InterSystems IRIS Native API allows Python applications to interact directly with InterSystems IRIS through low-level access to its core data structures—specifically, globals, 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.

Note:

If you are using the Native API and the client is on same machine as InterSystems IRIS, Python and InterSystems IRIS communicate using shared memory by default, for greater performance. This option can be turned off if you need Python to communicate with InterSystems IRIS using a secure connection, or to simulate connecting from another machine via TCP/IP. See Creating a Connection in Python for details.

Note:

The Native SDK and Embedded Python both require you to import an iris module. Though the modules have some methods with similar names, they have separate APIs and are not interchangeable. For information on the iris module used by the Native SDK, see Native SDK for Python Quick Reference.

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.

For more information, see Introduction to the Native SDK for Python.

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.

For more information, see Working with External Languages.

PEX Framework: A Key Use Case for the Python Gateway

The Production EXtension (PEX) framework 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.

For more information, see Introduction to the PEX Framework.

Embedded Python

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.

In contrast, with Embedded Python, the Python runtime and the InterSystems IRIS runtime are contained in same process. This tight integration means faster database access and streamlined communication between Python and ObjectScript, the native InterSystems procedural programming language.

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

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, and deploy your Python code together with your ObjectScript code.

  • 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 ECP and sharding features to easily scale your applications.

You can run Embedded Python in one of two basic modes: InterSystems IRIS running inside the Python process or Python running inside the InterSystems IRIS process.

If you are ready to move beyond basic Python database access and fully embrace what InterSystems IRIS has to offer, Embedded Python is the path forward.

Note:

The Native SDK and Embedded Python both require you to import an iris module. Though the modules have some methods with similar names, they have separate APIs and are not interchangeable. For information on the iris module used by Embedded Python, see InterSystems IRIS Python Module Reference.

Note:

Virtual environments are not currently supported for Embedded Python, as it uses the specific Python executable specified in the Embedded Python configuration. Client-side Python code can be deployed in a virtual environment, and you can have multiple virtual environments on the same machine that connects to the same InterSystems IRIS process. 

InterSystems IRIS Running Inside the Python Process

In this mode, you use the command irispython to call in to InterSystems IRIS. By running irispython myscript.py from the command line, your Python script runs in the same process with InterSystems IRIS, while your Python code remains separate from any ObjectScript code. This code separation allows you to use all your customary Python development practices: such as debuggers, linters, and syntax coloring tools.

Python Running Inside the InterSystems IRIS Process

In this mode, InterSystems IRIS calls out to Python. There are several ways to initiate Python from InterSystems IRIS, each with specific use cases, for example:

  • Write a method in an InterSystems IRIS class using the keyword [ Language = python ]. This is useful when you have an existing InterSystems IRIS class and you want to add a simple method written in Python.

  • Use the Import() method of the %SYS.PythonOpens in a new tab class in InterSystems IRIS. This is useful when you want to import a Python module from ObjectScript in order to perform a well-defined task.

  • Launch the Python shell from the Terminal using the Shell() method of the %SYS.PythonOpens in a new tab class. This is useful for testing a few lines of Python code interactively from within the InterSystems IRIS environment.

For larger-scale Python development, InterSystems recommends calling in to InterSystems IRIS from a .py file using irispython.

Note:

When Python is running within InterSystems IRIS, it is operating in a environment with multiple processes, users, home directories, and permissions. This results in added complexity that can sometimes make it more difficult to diagnose an issue when using Embedded Python.

Choosing the Right Path for You

It is important to choose the right Python option 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 or pyODBC Native API Python Gateway Embedded Python
Client Applications Yes Yes No No
SQL Stored Procedures, Functions, Triggers No No Possible Yes
Augmenting existing InterSystems IRIS Classes No No No Yes
Interoperability No No Yes (PEX) Possible
Manipulating Globals No Yes Yes Yes

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; importing a third-party Python module for use in an existing ObjectScript application Embedded Python Runs inside the InterSystems IRIS kernel; lowest latency and tightest integration with the data; makes it possible to use popular Python packages from ObjectScript
FeedbackOpens in a new tab