How to start IPython Notebook with a specified namespace

I have a GUI based application (TraitsUI / PyQt / Envisage) written in Python. I would like to create an IPython Notebook in which I show a small API and a few objects. These objects include a SQLAlchemy session and a bunch of SQLAlchemy models.

I watched a lot, but I can not find examples of this. I can start the laptop:

from IPython.frontend.html.notebook import notebookapp app = notebookapp.NotebookApp.instance() app.initialize() app.start() 

and this works quite well (although I would prefer the "start" to be non-blocking ... I assume I can do this in a different thread if necessary), but I cannot change the namespace.

I also found such examples:

 from IPython.zmq.ipkernel import IPKernelApp namespace = dict(z=1010) kapp = IPKernelApp.instance() kapp.initialize() # Update the ns we want with special variables auto-created by the kernel namespace.update(kapp.shell.user_ns) # Now set the kernel ns to be ours kapp.shell.user_ns = namespace kapp.start() 

But I'm not sure how to actually open a laptop here.

Does anyone have any suggestions?

Thanks!

+6
source share

Source: https://habr.com/ru/post/918003/


All Articles