Article
· Mar 26 3m read

Create business processes with custom Python code: a quick guide

Hello interface engineers and app developers,     

Did you know that you can use Python in productions or integrations?

The production configuration user interface is low-code, but in many projects, you may reach a point where you need to write some code. As discussed in the Integration Architecture course, business processes are full of places for inserting code, specifically the BPL editor (for BPL business processes) and the DTL editor (for data transformations).

😯 As of InterSystems IRIS 2025.1, both Python and InterSystems ObjectScript are supported in the BPL and DTL editors. 😄 You can decide between these languages based on your personal preference, not technical necessity. 😍

Write Python in the BPL Editor

Python is supported in the BPL editor as of InterSystems IRIS 2024.1. Let’s look at a BPL business process:

A BPL business process, including the following activities in order: a start activity, an assign activity, a code activity with a Python logo on it, an if activity with a Python logo on it, a transform activity on the true side of the if activity, and an end activity.

On the <code> activity, GetWinningBid, notice the Python icon. Opening that <code> activity, we can see the field labeled Code has Python statements written in it! These code statements use the built-in iris library to open an object of a given ID.

A code activity from a BPL editor. The language is set to Python. The code says # Use request body to open Bid object with given ID. New line. bidID = request.id. New line. context.winningBid = iris.cls("AuctionServer.Bid")._OpenId(bidID).

You can set the language for the entire BPL—Python or ObjectScript—via the Language setting under the BPL’s General settings tab, and use the Language Override drop-down menu on a given code field to override the BPL default.

The <code> activity is not the only activity that parses code in a BPL business process. The <code> activity parses full code statements, but other fields in BPL activities also accept code expressions. You can recognize these by their Language Override drop-down menu, where you can override the BPL default. 

For example, the <if> activity, which creates a conditional logic flow, has a field called Condition which accepts code expressions. It has a corresponding field called Condition Language Override. In this example, this field is set to Python.

Before Python was supported in these fields, interface engineers needed to know how to write logical expressions in ObjectScript. For example, you needed to know that || means or, and && means and. Now you can use Python, whose syntax for logical expressions is closer to natural language.

In the BPL editor, if you need to import Python packages, you can do so under Python From/Import statements in the General tab.

Write Python in the DTL Editor

Python is also supported in code fields of the DTL editor as of InterSystems IRIS 2025.1. Common uses for custom code in DTLs are string formatting and calculations.

A DTL data transformation converting a source object, AuctionServer.Bid, into a target object, AuctionServer.Order

If you need to import Python packages in the DTL editor, find the Transform settings tab and use the Python From / Import statements field. The default language for code expressions can also be set in the Transform settings tab.

In the Transform settings tab of a DTL, the language is set to Python and the Python From / Import statements field says from numpy import random.

To find the code-parsing fields of DTL actions, simply find any field associated with a Language Override drop-down. For example, in the <code> action of a DTL, you can write full code statements. Actions including set, if, trace, and others support code expressions, which can be written in Python or ObjectScript.

A code activity from a DTL data transformation, with the language set to Python. The contents of the code field say bidders = [bid.User for bid in source.Lot.Bids()]. New line. bidders = set(bidders). New line. target.NumOutbid = (len(bidders) - 1).

Code-first workflows

If you are familiar with the process of editing productions via code, you can edit BPLs and DTLs via their configuration files. This is not as user-friendly as the editor interfaces, but it is straightforward for experienced programmers.

You can also use Python to write methods in custom utility functions and custom components , such as business operations and business services (except for callback methods, as described in documentation).

Summary 

  • The DTL editor and BPL editor now support Python code and expressions. 
  • If needed, declare which packages you want to import via the BPL or DTL’s general settings. 
  • You can set a default language for each DTL/BPL and override specific fields as needed.

Join the conversation!

  • Have you ever used Python when creating custom integrations? 
  • What questions do you have about Python support in integrations?
  • Add your comments below!
Discussion (0)1
Log in or sign up to continue