How to import functions of a jupyter notebook into another jupyter notebook in Google Colab

You can use import_ipynb library.

First, mount your google drive to access your xxx.ipynb

from google.colab import drive
drive.mount("mnt")

Then change directory to the notebook directory.

%cd "mnt/My Drive/Colab Notebooks"

Now install the import_ipynb library, and import it

!pip install import-ipynb
import import_ipynb

Now you can import your xxx.ipynb

import xxx
xxx.do_something()

Here's an example Colab.

Update (oct 2020)

I have made the process easier, by just installing kora and call a function.

(Please also use auto-mount in a new notebook)

!pip install kora -q
from kora import drive
drive.link_nbs()

Now you can import from any notebooks you made before. For example, if you already have mylib.ipynb you can

import mylib
mylib.do_something()