How can you get a list of the currently running Jupyter Notebook Servers in python?
There is a jupyter-notebook
command to list the current notebook servers
machinename:~ username$ jupyter-notebook list
http://localhost:8888 :: /Users/username/your/notebook/path
http://localhost:8889 :: /Users/username/your/other/notebook/path
...
How can this be done in python without going to the command line and parsing the output?
By default, a notebook server runs locally at 127.0. 0.1:8888 and is accessible only from localhost . You may access the notebook server from the browser using http://127.0.0.1:8888 .
To check the Python version in your Jupyter notebook, first import the python_version function with “ from platform import python_version “. Then call the function python_version() that returns a string with the version number running in your Jupyter notebook such as "3.7. 11" .
You simply type jupyter lab into your terminal and Jupyterlab will open in your browser, with the Notebook server running in your terminal.
To launch a Jupyter notebook, open your terminal and navigate to the directory where you would like to save your notebook. Then type the command jupyter notebook and the program will instantiate a local server at localhost:8888 (or another specified port).
The list of running notebook servers may be accessed from within python via the actual python notebookapp
program by calling list_running_servers()
.
from notebook import notebookapp
servers = list(notebookapp.list_running_servers())
print(servers)
[{u'base_url': u'/',
u'hostname': u'localhost',
u'notebook_dir': u'/Users/username/your/notebook/path',
u'pid':123,
u'port': 8888,
u'secure': False,
u'url': u'http://localhost:8888/'},
...
{u'base_url': u'/',
u'hostname': u'localhost',
u'notebook_dir': u'/Users/username/your/other/notebook/path',
u'pid': 1234,
u'port': 8889,
u'secure': True,
u'url': u'http://localhost:8889/'}]
This also gives you more information than the command line interface. \o/-nice!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With