Make a runnable link to Colaboratory notebook

Viewed 9299
3 Answers

First take the ID part from the Drive URL. Here the ID is 0B88HiG_KpEbQcVhNa1NpZzVrT3c

Then put it in the fileId parameter in Colab URL, like this. https://colab.research.google.com/notebook#fileId=0B88HiG_KpEbQcVhNa1NpZzVrT3c&offline=true&sandboxMode=true

Notice the offline and sandboxMode parameters. Without them, the notebook will be read-only. In that case, you need to either duplicate it or change to playground mode to make it runnable

update

Newer URL is in this format instead:

https://colab.research.google.com/drive/0B88HiG_KpEbQcVhNa1NpZzVrT3c#offline=true&sandboxMode=true

Easiest method- when the notebook is open in Colab:

  1. Click the Share button in the top right.
  2. Copy the link provided at the top of the Sharing dialog.
from google.colab import auth
from googleapiclient.discovery import build
import io
from googleapiclient.http import MediaIoBaseDownload
import pandas as pd

auth.authenticate_user()
drive_service = build('drive', 'v3')

file_id = '1h1z-vGcNk1pt2U9Q8g9NR_L14txKLEos'
request = drive_service.files().get_media(fileId=file_id)
downloaded = io.BytesIO()
downloader = MediaIoBaseDownload(downloaded, request)
done = False
while done is False:
    status, done = downloader.next_chunk()

df = pd.read_csv(StringIO(downloaded.getvalue()))
Related