Skip to main content

InterSystems Python Productions (Experimental Feature)

The intersystems_pyprod Python library is an open-source libraryOpens in a new tab provided by InterSystems. You can use it to create production elements entirely in Python, which you can then use within existing or new productions. The library supports a hybrid approach: you can seamlessly mix new Python-based components with existing ObjectScript-based ones, along with components written in other languages.

This page introduces the intersystems_pyprod Python library and provides an overview of how to use it. This page assumes familiarity with interoperability productions.

Note:

This Python library is currently an experimental feature.

Supported Elements

The intersystems_pyprod Python library enables you to create any of the following classes for use in productions. In general, you subclass these classes:

  • Message classes

  • Business services (also known as inbound hosts)

  • Business process (also known as process hosts)

  • Business operations (also known as outbound hosts)

  • Inbound and outbound adapters

The library also provides the following helper elements needed to follow the code patterns used in interoperability productions:

  • The Status class for use in returning status values.

  • The IRISLog class for use in adding log entries (of different types) to the Production Log Viewer.

  • The IRISProperty class, which enables you to define user-configurable settings. A variable defined via IRISProperty becomes a property in an InterSystems IRIS class definition.

  • The IRISParameter class, which enables you to define the InterSystems IRIS class parameters. You use this to define ADAPTER parameter needed to connect a business host class to an adapter class.

Installation and Setup

At a high level, the installation and setup process is as follows:

  1. Create a Python virtual environment and use pip install to install intersystems_pyprod into it.

  2. Use pip install to install intersystems_pyprod into the directory structure accessible by InterSystems IRIS.

    In particular, it should go into <install-dir>/mgr/python

  3. In the InterSystems IRIS instance, enable the service named %Service_Callin.

  4. Also in the InterSystems IRIS instance, if you do not yet have a production, create a new namespace that is interoperability-enabled.

  5. Define environment variablesOpens in a new tab for use by intersystems_pyprod; these include information needed to connect to the InterSystems IRIS namespace that you plan to use.

For complete installation instructions, see pyprod - InstallingOpens in a new tab on GitHub (but do not use ENSLIB as the globals or routines database for the namespace; the ENSLIB database is replaced upon upgrade).

Defining Production Elements

To define production elements in Python, use the following overall process:

  1. To start, review the contents of the API referenceOpens in a new tab page, which you will need to consult for all details mentioned here.

  2. In a Python script, import the elements needed from intersystems_pyprod, as well as any other elements you need for other purposes.

  3. Also set the iris_package_nameOpens in a new tab variable in this script. This variable specifies the name of the package to create in the InterSystems IRIS namespace, to contain the classes that will be generated from your Python classes.

    You can specify this variable at the module level or at the class level as needed.

  4. For each production element that you want to define:

    1. Choose the appropriate class from intersystems_pyprod and create a subclass.

      For example, to create a business service, subclass BusinessService.

      The API referenceOpens in a new tab page lists the class needed in each case.

    2. In your subclass, implement any required callback or callbacks, using the method signatures provided in the API referenceOpens in a new tab.

      Message classes do not include callbacks, but the other production elements do.

    3. To define custom settings, use the following technique:

      • Use IRISPropertyOpens in a new tab to define a variable whose name will be used as the setting. With IRISProperty, you can specify the default value of the setting. You can also specify a description and a SETTINGS string, which controls how the Production Configuration page displays the setting.

      • Within your implementation of the callback, use the variable defined by IRISProperty.

    4. To connect a business host class to an adapter class, use the following technique:

      • In the business host class, use IRISParameterOpens in a new tab to define a variable named ADAPTER (case-sensitive). You must specify a value, which must exactly match the name of the InterSystems IRIS adapter class, including the package (determined by the iris_package_name variable).

      • Within your implementation of the callback, use properties or methods of the adapter class as needed.

    5. Use IRISLogOpens in a new tab to add logging information that is automatically visible within the Management Portal.

Loading Components into InterSystems IRIS

After defining the elements in Python, you load them into a namespace in InterSystems IRIS and add them to your production.

The process is as follows:

  1. Make sure that the environment variablesOpens in a new tab specify the desired namespace.

  2. From a command line session where you configured the environment variables, run the intersystems_pyprod command and provide the path to your Python script as an argument. For example:

    $ intersystems_pyprod /full/path/to/HelloWorld.py
    
        Loading HelloWorldBP to IRIS...
        ...
        ...
        Load finished successfully.
    

    This process uses your Python script to generate InterSystems IRIS class definitions that you can then use within interoperability productions.

  3. Create a new production or open an existing one, in the same namespace. Then add your new Python-based business hosts to this production in the same way that you would any other business hosts.

  4. Run the production in the same way you would run any other production.

See Also

FeedbackOpens in a new tab