Links between IPython notebooks

Question:

Is it possible to link one IPython notebook to another with a hyperlink in a Markdown cell? If I try

Link to [Notebook 2](files/notebook2.ipynb)

or

Link to <a href="files/notebook2.ipynb">Notebook 2</a>

A new tab is opened with raw unformatted contents of the ipynb file. Is there a way to get IPython to open another notebook for use in a new tab via a hyperlink?

Asked By: Mike

||

Answers:

Unfortunately, this is not practically possible.
The link would need to be to the notebook ID
(e.g. /a1e2a88f-3b91-4a4e-8ca1-d4fd7240f750 for the one I’m working on right now).
This is an UUID created at startup by the IPython server.
So you can copy the link from IPython Dashboard, but it will be valid only until you restart.

Answered By: lRem

From http://python.6.n6.nabble.com/where-is-the-code-to-generate-IPython-Notebook-URL-for-a-new-ipynb-file-td4996991.html:

You can access a json version of all the notebooks from url: $host/notebooks

Here is a snippet that worked for me:

    import urllib2
    import json
    data = urllib2.urlopen("http://127.0.0.1:8888/notebooks")
    json_data=data.read()
    list_o_dicts=json.loads(json_data)
    for d in list_o_dicts:
        if d['name'] == 'test':
            print d['notebook_id']

Modify this according to your need.

** on further reading, I just realized OP was also seeking new notebook creation, keeping my answer anyway as way to work with linking existing notebooks.

One way to try for OP’s goal is to run a script which will create a new notebook.ipynb file into the ipython folder where ipython notebook was started from. That .ipynb file can be templated from a new ipython notebook created from dashboard, with the name and id of the notebook replaced with whatever you are trying to link from your existing notebook. I have not tried this, but should work since dropping a .ipynb extension file into ipython folder does show it up in the dashboard.

Answered By: nom-mon-ir

It is now possible to do this with Ipython 1.0+ at least.

Just do:
localhost:8888/My Notebook.ipynb

Here is the documentation for this feature.
https://github.com/ipython/ipython/pull/3058

Answered By: DavidA

Since IPython 2 you may use exactly the syntax you first tried:

Link to [Notebook 2](notebook2.ipynb)
Answered By: akim

In addition to akim’s suggestion – you can link to any (py or ipynb) file using a relative link, starting with “edit”, and and then from the directory where you started the server.

E.g. in a markdown cell, if I want to reference a file whose relative location (relative to my git repo, which is also where I launched the notebook server) is “./path/to/source.py”, I’d add:

[link to source](/edit/path/to/source.py)

Answered By: Peter

Remember that if your file name has spaces you will need to replace those with %20

eg:

[Numpy](Numpy%20For%20Python.ipynb)
Answered By: Nick Leech
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.