I'd like to be able to know the base URL of the Jupyter Notebook server IPython is presently connected to. I'm aware of the notebook.notebookapp.list_running_servers()
function which produces output like:
[
{
'base_url': '/',
'hostname': 'localhost',
'notebook_dir': '/home/username/dir-notebook-was-spawned-in',
'password': False,
'pid': 368094,
'port': 8888,
'secure': False,
'sock': '',
'token': '4e7e860527d5333306cb06c594aa2167a7d375294f96c2d9',
'url': 'http://localhost:8888/',
},
...
]
This feels tantalizingly close to what I want since there's a base_url
key there, however I don't know how to determine which server in the list is where IPython is actually connected to. The closest approximation I've been able to come up with is to see which server's notebook_dir
key most closely matches os.getcwd()
but this is obviously imperfect.
Further Findings:
- I've now realized that
notebook.notebookapp.list_running_servers()
is not the right way to go about this because the notebook server and the kernel are not guaranteed to be running in the same place and in that case the function would always return an empty list.