Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extension that executes shell or python code

See original GitHub issue


I’d like to create an extension that runs some shell or python code. From what I’ve been able to find (mainly this: and a failed attempt at using child_process or zx from the src/index.ts file I have not managed to execute any shell code from an extension. I am trying to replicate the toolbar button example but executing some shell code (could be python too - but ideally shell) when the button is clicked

Proposed Solution

I have also tried adding the following (to no success):

const { exec } = require("child_process");

exec("ls -la", (error, stdout, stderr) => {
    if (error) {
        console.log(`error: ${error.message}`);
    if (stderr) {
        console.log(`stderr: ${stderr}`);
    console.log(`stdout: ${stdout}`);

Any help is appreciated, also I’d love to see an example of this feature if it’s possible at all

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

bollwyvlcommented, Jul 17, 2022

Where possible, you’ll want to use existing jupyterlab_server or jupyter_server REST API endpoints. These cover a lot of cases… indeed everything you see in JupyterLab!

To get really custom behavior, you’d extend the REST API with a python serverextension, and you can distribute both the static assets of the labextension and the handler in the same pip-installable package.

Of note: when the things you are calling are possible to be called directly from python, it can be useful to call them there, as you don’t have to worry as much about cross-platform concerns. nbconvert is such an example… but doesn’t have an asynchronous API. However, any time your code “blocks”, e.g. with subrocess.check_output it will block the whole system, and no other server methods will fire. For a while now, we’ve had anyio at our disposal, which has good support for cross-platform, async processes .

luis-chaves-visacommented, Aug 10, 2022

Hey @bollwyvl and @jasongrout, thanks for your replies!

After some digging I’ve gone down the server extension way. I still have some issues though, regarding how to get the current notebook path as @paugier is asking in #203. I’ll write another issue for clarity

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Shell
A Python shell for Chrome. You can use Python Shell to test Python code or as a learning tool. It is a complete...
Read more >
5 Must-have Chrome Extensions for Python - TechBeamers
1- Python Shell Extension by Sam Clegg · 2- QuickPy Python Interpreter · 3- Python Fiddle by · 4- Python Shell by...
Read more >
Python in Visual Studio Code
Working with Python in Visual Studio Code, using the Microsoft Python extension, is simple, fun, and productive. The extension makes VS Code an...
Read more >
Python Interpreter: Shell/REPL - TutorialsTeacher
It means it executes the code line by line. Python provides a Python Shell, which is used to execute a single Python command...
Read more >
Run Python Script – How to Execute Python Shell Commands ...
py extension, typically called Python scripts. Then you execute them from the terminal using the Python command. All the commands we executed ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found