Thank you for your answer!
I am also thinking about a jupyterlab plugin which enables the communication with the Kernel.
However, I am unsure on how to exactly "trigger" the custom plugin.
So, imagine, I have a Python script. And when I run this script or a line of Python (maybe the script is also located in a library), I want this to not only execute the current cell but also paste code into the next cell AND execute the next cell. Because I am basically "auto-generating" multiple separate outputs for the user.
One possible solution that I see right now is that my custom plugin could listen to the execution of cells and check if there is some special code inside and then trigger some custom Javascript action to add a new cell, fill it with necessary code and execute it.
However, this does not feel right. Also, the content of the next cell might be variable based on the results of the "initial" cell.
Is there a better way of triggering my plugin from Python code for this specific scenario? In the ideal case, I can call a function in my extension and pass it some arguments from Python. This seems similar to a display() call where another extension is triggered to handle the display of the output. So, this seems related but maybe not completely?