Q: How do I access objects in user namespace with jupyter_client? I want to execute cells in an IPython / Jupyer notebook programmatically and do some introspection on them, like getting user variables.
With IPython.core.InteractiveShell it is quite easy:
from IPython.core.interactiveshell import InteractiveShell
shell = InteractiveShell()
shell.run_cell("foo = 1")
assert shell.ns_table['user_local']['foo'] == 1

I cannot user InteractiveShell though because I want to capture rich output (as discussed in another question). In order to do that, I have to use jupyter_client which uses a ZeroMQ connection to the kernel.
My question is, how can I retrieve object from the namespace of an IPython kernel, the way ns_table does in the above example? Is some kind of boilerplate code injection into cell source and/or pickling/unpickling of user expressions unavoidable (as discussed in yet another question)?
