5

I have a Python file available under some URL, for example

https://gist.githubusercontent.com/messa/d19ad7fd4dc0f95df9caf984caef127c/raw/4d0daebdcfcf16ea3b7914ee6186bd98dbfb3c20/demo.py

In reality it will not be gist but some courseware/homework review software.

How can I open such URL using Google Colab so I can for example run the Python code?

I know I can build colab URL for Github gists or repositories, but can I do it for any arbitrary URL?

5
  • What are you trying to do? You can of course !wget a URL as that, but it seems like there is some larger workflow you are trying to support... Commented Sep 1, 2018 at 20:33
  • @BobSmith You would have to open new notebook and type !wget or copy-paste the code or something. But I want the code to just appear in the new Colab notebook, without doing anything more than clicking on a link. Commented Sep 1, 2018 at 20:37
  • The simplest way is to put the code in a notebook and then share a link to the notebook. What excludes that approach? Are you seeking a way to convert a .py file into a notebook? Commented Sep 1, 2018 at 20:53
  • I want to do it automatically. This would be ok it Colab had API for creating new notebook. (What I can do right now is to use Github API to create gist and then generate Colab URL for that gist, because Colab supports Github gists/repos, but that’s not very nice.) Commented Sep 1, 2018 at 21:01
  • Imagine you have dozens of homework submissions in form of small python files in some web app. I would like to provide a way to run them in Colab as easy and quick as possible. Just click somewhere and open that file in Colab. Or possibly in some Colab alternative. Commented Sep 1, 2018 at 21:03

2 Answers 2

15

There is currently no way to do what you are asking for – to construct a URL that will cause Colab to automatically load the contents of a .py file at a particular URL into a new Colab notebook.

The closest thing to this is to host a notebook on github, and then use a Colab url to open it: (updated based on https://colab.research.google.com/github/googlecolab/colabtools/blob/main/notebooks/colab-github-demo.ipynb#scrollTo=K-NVg7RjyeTk) e.g.

  • http://github.com/username/repository/path/to/notebook.ipynb can be opened in Colab using http://colab.research.google.com/github/username/repository/blob/main/path/to/notebook.ipynb
  • http://gist.github.com/username/hash/filename.ipynb can be opened in Colab using http://colab.research.google.com/gist/username/hash/filename.ipynb
Sign up to request clarification or add additional context in comments.

1 Comment

As of June 2021, it seems it is still not possible to open Jupyter notebook files (.ipynb) from an URL in Google Colab. Here is a Feature Request in the Google Colab's repo. Chip in with your votes there so the issue gets some visibility.
0

There is an option now in the google colab to directly add a github link of a jupyter notebook. That will open the notebook in the google colab.

Open Notebook >> Github >> paste the link in the dialog box.

To open a notebook of your private repository, you can now integrate your github profile to google colab as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.