Python3 Binding (Discussion)

a new bug fix and feature release, with a detailed changelog, is available in the marketplace

The most noticeable breaking change is that no jsr223 objects are injected in the global frame by default anymore. You have to use one of the following import syntax instead.

from scope import * # this makes all jsr223 objects available globaly and restores the beavior like before
print(ON)

or

from scope import ON, OFF # this imports specific jsr223 objects
print(ON)

or

import scope # this imports just the module
print(scope.ON)

You can also import additional jsr223 presents like

from scope import RuleSimple
from scope import RuleSupport
from scope import RuleFactories
from scope import ScriptAction
from scope import cache
from scope import osgi

or just openhab core classes

from org.openhab.core import OpenHAB
print(str(OpenHAB.getVersion()))

another huge improvement is the fix of the last major known bug related to duplicate truffle library loading. The fix works only in openhab 5. This means, you still have to live with the workaround for openhab 4, but you can look forward to openhab 5 even more. :slight_smile:

btw. The workaround for openhab 4 does not mean you can’t use it for your production setups. This just mean, during a bundle update, you have to restart openhab several time until the exception disapears. After that, everything runs normal. I personally run succesful ~10.000 lines of python code in 133 rules. And I use the python binding as a transformation service with success too.

2 Likes