Article
· Jul 8 3m read

WSGI Support Introduction

wsgi_logo

Context

The Web Server Gateway Interface (WSGI) is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. WSGI is a Python standard described in detail in PEP 3333.

🤔 Ok, great definition and what the point with iris ?

IRIS 2024.2+ has a new feature that allows you to run WSGI applications directly on IRIS. This feature is a great way to integrate IRIS with other Python frameworks and libraries.

This goes in the trend of Python first experience, where you can use Python to interact with IRIS, and now you can also run Python applications directly on IRIS.

How to use it

To instantiate a WSGI application on IRIS, you need to configure it in the Security->Applications->Web Applications section of the IRIS Management Portal.

Simple flask example:

File called app.py in /irisdev/app/community directory:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

UI Configuration

image

In this section, you can configure the WSGI application by providing :

  • Aplication Name

    • this corresponds of the file name of the WSGI application
    • ex: app.py but without the .py extension : app
  • Callable Name

    • the callable function that will be called by the WSGI server
    • ex: app corresponds to the app variable in the app.py file

    • app = Flask(__name__)

  • WSGI App directory
    • the path where the WSGI application is located
    • ex: /irisdev/app/community
  • Python Protocol Type
    • it can be wsgi or asgi
    • wsgi is the default value and the one used in this example
    • asgi is for asynchronous applications
      • we support asgi syncrhonously for now with the a2wsgi adapter
  • DEBUG
    • if checked, the WSGI application will run in debug mode
    • this is useful for development purposes as any changes to the WSGI application will be automatically reloaded

CPF Merge

You can also configure the WSGI application using CPF. Here is an example of the configuration:

[Actions]
CreateApplication:Name=/flask,NameSpace=IRISAPP,WSGIAppLocation=/irisdev/app/community/,WSGIAppName=app,WSGICallable=app,Type=2,DispatchClass=%SYS.Python.WSGI,MatchRoles=:%ALL,WSGIDebug=0,WSGIType=0

Log Files

The WSGI application logs are stored in the WSGI.log file located in the mgr directory of the instance.

Examples

Here are some examples of WSGI applications that you can run on IRIS, they aim to show how to run different Python frameworks on IRIS.

Basically, the use case will be the same for all the frameworks:

Endpoints

  • /iris - Returns a JSON object with the top 10 classes present in the IRISAPP namespace.
  • /interop - A ping endpoint to test the interoperability framework of IRIS.
  • /posts - A simple CRUD endpoint for a Post object.
  • /comments - A simple CRUD endpoint for a Comment object.

Object Model

Post object:

  • id
  • title
  • content

Comment object:

  • id
  • post_id (foreign key to Post)
  • content

Flask

Django

FastAPI

Limitations

  • The ASGI is supported synchronously for now with the a2wsgi adapter.
  • tornado applications ( jupyter, streamlit, .. ) are not supported as they are not WSGI compliant.
Discussion (0)1
Log in or sign up to continue