I want to have a Python application - complete in itself - that allows the user to extend it via scripting (or a plugin model) in Python. But I want the script/plugin to have an isolated environment (within the same process) to run in. How do I do this?
- For concreteness - the app performs dynamic geometry visualization and I want the user to extend the visualization with certain checks/constraints in addition to standard geometry/mechanics, etc. etc. But that doesn't actually matter.
I am not interested in isolation in the sense of security, or copyright/licensing, or anything like that. I don't care if the user parties arbitrarily on my code. I'm only interested in software engineering: I want to provide a Pythonic API (O-O) and the extensions should be able to use Python as it wants, talking to my application only through this API, and not interfere with the application itself running in the same Python instance.
So I don't want there to be trouble with global variables, or even singletons (e.g., that correspond to database or web connections). This is so that 1) I can know if the API I provide is sufficiently complete (if it isn't I'll extend it) and 2) so I can draw a line (the API) and if the user crosses it he knows he's on his own, support-wise.
It's possible what I'm looking for is a kind of Pythonic "sandbox", or maybe something like what in .NET is called an "Application Domain". But there needs to be communication between the app and the plugin via an object model - in Application Domains this is (or was) done with remote objects (automatically generated proxies via COM). (Automatically generated proxies sounds awfully familiar for Python but I can't put my finger on it right now ...)
[I tried searching for answer first, before consulting SE, as I always do, but all the search terms I thought of - context, scripting, plugin, environment, isolation - have other very well established ordinary meanings, even in the Python context, and even as Python class names, and so any result I was looking for was swamped in other results not answering this question. In fact, I'd consider an answer here on-point if it only told me what search terms to use so I could find the real answer myself. I fully expect to learn here the name of an already existing class or library that does what I want, if only I had known.]
[Partial solutions also would be great if they include an explanation of what the limitations are ...]
module.process()method to an API that's better suited for your needs.) Or did you have something more complicated in mind - perhaps involving separate Python packages, etc? Also: "an isolated environment" - could you clarify what you mean by that? Because python has this notion of virtual environments, but it doesn't seem like that's what you mean.