How to use Github Jupyter Notebook in Medium Blogs?

Often there is a requirement to integrate our Jupyter notebook with our medium blogs, however there is no straight way,other than putting up a Gist to make it possible. And again the gist needs to be synced to keep it up to date with the Github repo notebook version. Do we have any automated way?

Creating a gist:

Go to you GitHub. In the top right corner find the “+” button and select “New Gist”:

Post the whole notebook.

  1. Drag and drop your existing Jupyter Notebook into the new gist window, it will look like this:

2. Save the new gist, make sure it saves the file as a .ipynb file, otherwise edit and save as we did above. It is important to save as .ipynb and NOT as .py, because here you are saving the notebook not just python code. If all goes well, it will look like this:

3. Copy the link from your browser

…and paste in your medium post: voila!

Ok, cool! What if the notebooks needs constant updates ? how to automate instead of manual updates every time?

Jupyter notebooks needs to be enabled to push the file without asking for
login credentials, for which creating `netrc` file will help.

Update the notebook, and execute a cell that clones, updates the gist file and pushes it back to the master. That way we don’t have to worry of syncing the notebook with Gist.

On last Jupyter cell:

  • Clone the gist file
  • Copy the notebook file
  • Commit the file
  • Push the file

Tada your gist is updated and your blog is up to date with your latest data! Happy blogging!