Python Objective-C Bridgebrowsing

I'm pretty sure I can call back into Objective-C by writing a statically compiled python library with the functions I want in it (I can see examples of this in places like scene.py and canvas.py (e.g. import _canvas)). BTW, an example would be great, since those libs are compiled into the libpythonista.a lib I can't see what they look like, but I can probably figure it out.

My question is - is the reverse possible ? I want to call a python function from Objective-C. In the PyObjC world I would have imported objc and then created a python subclass of a NSObject. I was hoping you could provide any pointers on how I would go about this.

Also, how would global variables work ? If I were to call a python function and it declared a globalvariable then returned and then I was to call another function that used the same global variable, would it be available ? Would python keep its memory space around between calls ?

If you use the Xcode template, it would generally be possible to add additional native functionality that is accessible from Python in the same way, but it would NOT be possible to add such functionality to the Pythonista app itself.

As an example, this is an abridged and simplified version of the _clipboard module:

Implemented such a coding like the clipboard example , called the module “_sensors”
Compiling and linking was done without any errors.
Then I added “import sensors” to my main.py file and got the error during runtime that the module is not defined.
What is missing ?

Did you write a corresponding sensors.py file? If you implement _sensors in C (or in Python, it doesn't really matter) that doesn't automatically create a sensors module. The point of having a native C module and a separate Python wrapper is so you can write parts of your library in Python, and so you can change the C interface without worrying about breaking user code. (Of course you'd still need to provide some backwards compatibility in the Python module.) The C library is still normally available to Python code as _sensors, the underscore is used as a convention to indicate that it is a "private" library that external code should not depend on.