# How to get URL of current Jupyter notebook?

**URL:** <https://discourse.julialang.org/t/how-to-get-url-of-current-jupyter-notebook/9851>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 21, 2018, 6:18am UTC](https://discourse.julialang.org/t/how-to-get-url-of-current-jupyter-notebook/9851 "2018-03-21T06:18:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [March 21, 2018, 6:18am UTC](https://discourse.julialang.org/t/how-to-get-url-of-current-jupyter-notebook/9851/1 "2018-03-21T06:18:00Z")

</div>

Let’s say you’re inside a jupyter notebook.

How do you find the URL of the current page?

* * *

This should be equivalent to if you just did the following in the javascript console:

> `window.location.href`

// this assumes you know you’re in [IJulia](https://github.com/JuliaLang/IJulia.jl#detecting-that-code-is-running-under-ijulia)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 21, 2018, 10:23am UTC](https://discourse.julialang.org/t/how-to-get-url-of-current-jupyter-notebook/9851/2 "2018-03-21T10:23:12Z")

</div>

Even getting the name of the notebook is tricky and undocumented:

[https://github.com/jupyter/notebook/issues/1000](https://github.com/jupyter/notebook/issues/1000)

Once you have the name, I think you can use the contents of `IJulia.connection_file` to work out the URL.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [March 21, 2018, 6:21pm UTC](https://discourse.julialang.org/t/how-to-get-url-of-current-jupyter-notebook/9851/3 "2018-03-21T18:21:33Z")

</div>

So, I’m still a little stumped at how that information would get you to a full url.

* * *

in julia,

```julia
> readlines(open(IJulia.connection_file))

12-element Array{String,1}:
 "{"                                                
 " \"shell_port\": 45415,"                         
 " \"iopub_port\": 56344,"                         
 " \"stdin_port\": 55505,"                         
 " \"control_port\": 34104,"                       
 " \"hb_port\": 55104,"                            
 " \"ip\": \"127.0.0.1\","                         
 " \"key\": \"8f542a78-191098430b8bad7b07401613\","
 " \"transport\": \"tcp\","                        
 " \"signature_scheme\": \"hmac-sha256\","         
 " \"kernel_name\": \"julia-0.6\""                 
 "}"                                                

```

in python,

```python
> get_notebook_name()

/home/jovyan/Carthage.jl.ipynb

```

With the following found in the process:

`{'base_url': '/user/djsegal-carthage-binder-9195qzmy/', 'hostname': '0.0.0.0', 'notebook_dir': '/home/jovyan', 'password': False, 'pid': 1, 'port': 8888, 'secure': False, 'token': 'j03TaCw7Qoun35S4-dCtjQ', 'url': 'http://0.0.0.0:8888/user/djsegal-carthage-binder-9195qzmy/'}`

`{'id': 'f10cccfe-449b-4f75-a91c-997ed9cc6952', 'path': 'Carthage.jl.ipynb', 'name': '', 'type': 'notebook', 'kernel': {'id': '38a072d1-ceed-4874-aa37-8da41a659dd4', 'name': 'python3', 'last_activity': '2018-03-21T18:06:35.476223Z', 'execution_state': 'busy', 'connections': 1}, 'notebook': {'path': 'Carthage.jl.ipynb', 'name': ''}}`

* * *

Do you know any other puzzle pieces that might exist?

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [March 21, 2018, 6:50pm UTC](https://discourse.julialang.org/t/how-to-get-url-of-current-jupyter-notebook/9851/4 "2018-03-21T18:50:43Z")

</div>

Or maybe more importantly, how do you get this python function in Julia:

```julia
> list_running_servers

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 21, 2018, 9:52pm UTC](https://discourse.julialang.org/t/how-to-get-url-of-current-jupyter-notebook/9851/5 "2018-03-21T21:52:22Z")

</div>

> [@djsegal](#):
>
> Or maybe more importantly, how do you get this python function in Julia: `list_running_servers`

Look [at its implementation in Python](https://github.com/jupyter/notebook/blob/97dd1ed9f3aea13de7ae051c1f9538a71277e034/notebook/notebookapp.py#L1666-L1694). It basically walks the Jupyter runtime directory. To get the runtime directory, [see here](https://github.com/jupyter/jupyter_core/blob/616447137a99f2437f7270dd3d8382091fb3df97/jupyter_core/paths.py#L88-L110).

All straightforward stuff to re-implement in Julia, just needs someone to do it.
