Question
· Mar 6, 2023

Compatibility of Embedded Python and %CSP.REST

I'm curious about how embedded Python is handled by %CSP classes, particularly in the case of defining REST endpoints on IRIS.

Here is a simple dispatch class for the endpoint /api/pythonapp on my local IRIS instance (2022.3):

Class Python.App.Dispatch Extends %CSP.REST
{

XData UrlMap [ XMLNamespace = "https://www.intersystems.com/urlmap" ]
{
<Routes>
    <Route Url="/test" Method="GET" Call="Hello" />
</Routes>
}

ClassMethod Hello() As %Status [ Language = python ]
{
    import iris

    print('Hello World!')
    return True
}

}

Making a GET request to <ip:webport>/api/pythonapp/test does not return an error, but returns "wstr%SYS.csp" which is interesting.



Can anyone shed light on this behaviour or has achieved an embedded Python dispatch class without passing values to ObjectScript methods for writing? In reality, it might make more sense to build out APIs in Django or another framework and utilise DB-API for connectivity, but I'm curious about whether this is workable.

Product version: IRIS 2022.3
Discussion (4)1
Log in or sign up to continue

I guess you need to flush the buffer so only python writes? Something like this should work:

Class Python.App.Dispatch Extends %CSP.REST
{

XData UrlMap [ XMLNamespace = "https://www.intersystems.com/urlmap" ]
{
<Routes>
    <Route Url="/test" Method="GET" Call="Wrapper" />
</Routes>
}

ClassMethod Wrapper()
{
	write *-3
	do ..Hello()
	q $$$OK
}

ClassMethod Hello() [ Language = python ]
{
    import iris

    print('Hello World')
}

}

Calling @Bob Kuszewski

I had an experiment with making a CSP framework for using embedded python.

https://github.com/alexatwoodhead/PyNow

It has some utility code that converts the %request arguments and presents as a dictionary to Python method.

It also shows using XData blocks to use as a template with some Excel function+Django like expression support.

Might find something reusable in there.