Executing a script to return value to openhab

I have a python code that prints value from 1-8 according to key press. i want to send that data to openhab to turn on and off lights. i cannot understand how i can do that. i tried using rest api but i am not good at it. if any other way please suggest.