Import switch status from openhab to python

Hello,
Is it possible to import from openhab the status of a switch to a python script.
Just like ON or OFF and this would take place in some variable in my python script.

Here’s a link to Rich’s sensorReporter https://github.com/rkoshak/sensorReporter maybe this will help with what you have in mind.

Brief description from the link:
A python based service that receives sensor inputs and publishes them over REST (should work with any API but mainly tested with openHAB) or MQTT. It can also receive commands and perform an action (e.g. set a GPIO pin to HIGH). It currently supports Bluetooth, GPIO on Raspberry Pi, Amazon Dash buttons, command line scripts, and Roku IP address …

I’m not sure that is what OP is asking for. It’s hard to tell.

If you want to send a command to an Item in OH and have it trigger something to run in your Python script then sensorReporter is one way to do it. Other options are the Exec binding or executeCommandLine.

However, if you want to check the state of an Item in OH to determine what your Python script does, you need to use the REST API. Install the REST API docs from the Misc tab in PaperUI and explore the various calls. To get the state I think you just issue a GET command to http//:ohaddress:8080/rest/items/itemname/state.