How to share variables from jupyter notebook to python script

Hello everybody,

I want to automatically share variables from a jupyter notebook (jupyter lab) to a running python script (local flask server).

For example, in my Jupyter cells, I generate via processing a Pandas DataFrame, which I can find in my Flask web page by reloading the page on my browser.

In fact, I would like to have a particular presentation of my DataFrames on which I work.

Is this possible?

Flask is going to be hard to interact with directly. You could theoretically launch it in a thread or something, and use deque to talk back and forth with it. Any async-compatible server can also run non-blocking within the same process as a kernel, as in:

Otherwise, you’d need some way for the kernel to talk to the flask server:

  • a REST API
  • dumb files on disk
    • dataframes might be a good match for e.g. arrow
    • or generate the html itself in the kernel, and just serve it

Or for flask to talk to the kernel:

  • again, see the above hosting a web application from within a kernel