Written by

Technical Consultant at Traverse Health
MOD
Question Muhammad Waseem · Feb 17, 2022

How to change namespace from embedded python?

Hi,

I am getting below error while using embedded python script.


Want to know how can I change namespace to %SYS to use above mentioned class?

Thanks

Comments

Robert Cemper · Feb 17, 2022

just do it in a classMethod in Objectscript
don't forget to return to your original namespace to find where you came from

0
Guillaume Rongier · Feb 18, 2022

For now, it's not possible in pure python, because the select namespace is specified by the environment variable IRISNAMESPACE, and environment variable can't be change in the parent process, I have tried by reloading iris module with no success.

To achieve that, for now, as Robert says, you have to create an helper method in objectscript ... :(

Class Embedded.Utils
{

ClassMethod GetNameSpace() As %Status
{

    Return $namespace
}

ClassMethod SetNameSpace(pNameSpace) As %Status
{
    zn pNameSpace
    Return $namespace
}

}

Python :

import iris

print(iris.cls("Embedded.Utils").GetNameSpace())
try:
    print(iris.cls("Security.Users").Exists("SuperUser"))
except RuntimeError:
    print("Wrong NameSpace")

print(iris.cls("Embedded.Utils").SetNameSpace("%SYS"))
try:
    print(iris.cls("Security.Users").Exists("SuperUser"))
except RuntimeError:
    print("Wrong NameSpace")
0
Robert Cemper  Feb 20, 2022 to Guillaume Rongier

But be aware to have the method SetNamespace available also the new target namespace to be able to return !
So you either map the class to Namespace %All,
or name the class %ZEmbedded.Utils or similar,  to make it available across all namespaces.

0
Muhammad Waseem  Feb 21, 2022 to Robert Cemper

Thanks Mr Robert for sharing the details

0
Robert Cemper  Feb 21, 2022 to Muhammad Waseem

Sorry. it just turned out that sharing across namespaces doesn't (yet?) work with embedded Python

0
José Pereira · Dec 21, 2025

In IRIS for UNIX (Ubuntu Server LTS for x86-64 Containers) 2025.1 (Build 204U) Thu Feb 13 2025 16:06:36 EST,  the following worked for me:

import iris

iris.execute('ZN "IRISAPP"')
0
Vitaliy Serdtsev · Dec 22, 2025

IRIS 2025.3.CE

ClassMethod test() [ Language python ]
{
  import iris

  ns = iris.system.Process.NameSpace()
  try:
    iris.system.Process.SetNamespace('%SYS')

    passenger = iris.SYS.Stats.Dashboard.Sample()
    print(passenger.GloRefsPerSec)
  finally:
    iris.system.Process.SetNamespace(ns)
}

PS: Do I need a separate python iris connection for each Namespace?

0