Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current jupyter notebook servers in python?

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?

like image 543
tmthydvnprt Avatar asked Jan 21 '17 17:01

tmthydvnprt


People also ask

How do I find my Jupyter Notebook server?

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 .

How do I check my Python version Jupyter Notebook?

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" .

How do I access the Jupyter Lab server?

You simply type jupyter lab into your terminal and Jupyterlab will open in your browser, with the Notebook server running in your terminal.

What command launches a Jupyter Notebook server?

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).


1 Answers

Accessing a list of running notebook servers from python

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!

like image 112
tmthydvnprt Avatar answered Sep 19 '22 05:09

tmthydvnprt