My desired outcome is a jupyter notebook running in the browser.
From another program (say a local editor) that has access to the kernel/back end of notebook, I would like to be able to call an api to append a cell with specified contents, execute the cell, and show the output.
The examples for programmatically doing seem to require running in the notebook itself. I would like to be able to just send code to be executed to the kernel, and have it output the result in the already running jupyter notebook. This should not require refreshing the page or anything like that, ideally.
Yes, acting as kernel client works fine, there’s just a number of keys that need to passed around, etc. However, the state of a notebook client is separate from that of the kernel… there isset_next_input but it won’t run anything, and not all clients implement it.
An approach that might work for your use case is ipylab which can run commands, which are probably the most stable way to interact with the lab client. Again, you’d need a handle to the kernel, but you’re probably going to need that anyway.