Connect ipython shell to running panel server

This would be a really nice supplement to interactive development loops with panel. Is it known how to do this easily?

Thanks!

Hi @LinuxIsCool

The next version of Panel (and the current master branch) contains a general purpose terminal based on xterm.js. You can easily run any terminal process including ipython using it.

Check out the Reference Notebook on Binder or PR.

ps. Depending on your use case you could also consider adding a python terminal that runs in the browser only. I have some code based on Brython. And it should also be possible to create one based on Pyodide.

1 Like

Thanks @Marc, the panel terminal is really cool.

However, I was thinking of something more like an ipython shell inside of my terminal when I run panel serve for example:

panel serve app.py --autoreload -i ipython

Similar to the django shell for those familiar.

Thanks!

Update!

The following seems to work:

import threading
from IPython import start_ipython

def start_ipython_in_thread(namespace):
    start_ipython(argv=[], user_ns=namespace)

# Pass the main thread's namespace to the IPython instance
ipython_thread = threading.Thread(target=start_ipython_in_thread, args=(globals(),))
ipython_thread.start()

Add the above code to your app.py.

Then when you serve:

panel serve app.py

Then your console will drop into ipython with the appropriate namespace after serving the app.

1 Like