Question
· Sep 8

Embedded Python pages in IRIS

Hi, 
 

My understanding is that IRIS comes with Embedded Python in it, how can create a page using Python instead or Zen or CSP Pages?
maybe a small sample (like hello python page) to get the idea.

Thanks  

Product version: IRIS 2024.3
Discussion (3)3
Log in or sign up to continue

To create a web page using Python in InterSystems IRIS instead of relying on Zen or CSP pages, you can utilize a Python web framework like Flask alongside Embedded Python. Here is an approach and example for a basic “Hello Python” page:

Approach

  • Install Flask in your IRIS environment and set up the necessary prerequisites for Embedded Python.
  • Define a Python script (e.g., using Flask) that starts a simple web server within IRIS.
  • Use iris library to interact with IRIS where needed.

Steps

  1. Install Flask:
    Use pip to install Flask directly into the IRIS directory for Python packages. Run:

    python3 -m pip install --target <path-to-iris-python-directory> flask
    
  2. Create a Flask App:
    Write a Python script for your Flask application. For instance:

    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route('/')
    def hello_world():
       return {'message': 'Hello Python Page'}
    
    if __name__ == "__main__":
       app.run(host='0.0.0.0', port=5000)
    

    Save this script (e.g., as app.py) in a directory accessible to IRIS.

  3. Set Up IRIS Integration:
    If needed, leverage the Embedded Python capabilities to load or manipulate IRIS data directly from the Python script. For example, using the iris library:

    import iris
    
    @app.route('/data')
    def get_data():
       # Example of interaction with IRIS database
       iris_obj = iris.cls('Namespace.Class')._New()
       iris_obj.Value = 'Test'
       iris_obj._Save()
       return {'data': iris_obj.Value}
    
  4. Run the Application:
    Start the Flask server from within your IRIS container or environment. Run the command:

    python app.py
    
  5. Access the Page:
    Open the web browser and navigate to http://<your-host>:<port> (e.g., http://localhost:5000). This should display your "Hello Python Page."

Notes:

  • Docker and IRIS dev containers can streamline configuration and ensure all dependencies for Embedded Python are correctly set.
  • This Python-based page doesn't require Zen or CSP and provides flexibility for modern web frameworks.

Feel free to explore more advanced options like REST APIs or embedding Python directly with other IRIS operations as required [1][1][2].

Sources:

You can use frameworks like the one suggested by the DC AI bot, Flask, or simpler and faster-to-learn frameworks such as Streamlit and Lovable. Take a look at these articles:
- building frontend using only python
- getting know python streamlit part 1
- getting know python streamlit part 2
- prompting ui intersystems fhir lovable
- video prompt frontend ui intersystems iris lovable

But in any case, you don’t need to use embedded Python for the frontend.