Answer a question

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?

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!

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐