Jupyter to Medium Initial Post
Tags: notebook, jupyter, datascience, python
Published: 2021-11-15 14:51:45

---
title: Jupyter to Medium Initial Post
published: true
date: 2020-06-02 12:50:36 UTC
tags: notebook,jupyter,datascience,python
canonical_url: 
---

### Automate Publishing of Jupyter Notebooks as Medium Blog Posts with jupyter\_to\_medium

I am very excited to announce the official release of [jupyter\_to\_medium](https://www.dexplo.org/jupyter_to_medium), a Python package that extends Jupyter Notebooks, allowing you to automate the process of publishing them as Medium blog posts.

#### Video Walkthrough

I created a video showing exactly how to deploy a notebook as a Medium blog post.

{% youtube lU9jogfXNqE %}

#### Motivation

I’ve published dozens of blog posts on Medium myself with all of them beginning as Jupyter Notebooks. Manually converting them to Medium posts was a fairly lengthy, painstaking process. One particularly painful process was inserting tables, which Medium does not support, into my posts. Nearly all of my posts contain numerous pandas DataFrames ([such as this one](https://medium.com/dunder-data/selecting-subsets-of-data-in-pandas-6fcd0170be9c), which has 40! DataFrames) which are represented as HTML tables within a notebook. I’d take screenshots of each one to insert them into my Medium posts.

jupyter\_to\_medium automates the process of converting Jupyter Notebooks to Medium blog posts allowing you to save a substantial amount of time.

#### Installation

Install from PyPI with the following command:

```
pip install jupyter\_to\_medium
```

After installation, fire up a Jupyter Notebook that you’d like to publish on Medium. Make sure you start a brand new notebook session. Even if you don’t have a notebook that is ready to publish, you can still test this extension and publish as a draft so that it remains private.

#### Deploy as Medium Post

Once you open your notebook, head into the **File** menu and notice that you’ll have a new option **Deploy as -> Medium Post**.

![Menu Option](https://cdn-images-1.medium.com/proxy/1*M_xkf53IMfXisfwTQSl6bw.png)

#### If ‘Deploy as’ option is missing

This new option should automatically show up in your notebook without doing anything. If it is missing, run the follow command to enable it.

```
jupyter bundlerextension enable --py jupyter\_to\_medium.\_bundler --sys-prefix
```

#### Fill out form

Clicking on **Deploy as -> Medium Post** triggers a new browser tab with a short form that needs to be filled out before posting.

![](https://cdn-images-1.medium.com/proxy/1*r6fWnWTZt2Wq73_3d_OFZA.png)

#### Medium Integration Token

Before you can post to Medium, you’ll need to request an integration token from them. Do this by emailing them at [yourfriends@medium.com](mailto:yourfriends@medium.com). Please read the [entire instructions on how to get your integration token](https://github.com/Medium/medium-api-docs#21-self-issued-access-tokens).

Once your request is granted, navigate to [your Medium settings page.](https://medium.com/me/settings) Towards the bottom of the page exists the section on **Integration Tokens**. Enter a description for the token (jupyter\_to\_medium is a good choice) and then create the token.

![](https://cdn-images-1.medium.com/proxy/1*kA8jVpLm3fJV-FgIsSH_8g.png)

#### Save your integration token

Once you have your integration token, create the folder and file .jupyter\_to\_medium/integration\_token in your home directory and save the token there. If you don't save it, you'll need to access it every time you wish to make a new post.

#### Complete form

Once you have your integration token, you can complete the rest of the form. Note that the ‘Title’ text box is not the actual title of the post, but a title that Medium uses for SEO purposes. Use an H1 Markdown header in the first cell of your notebook to create the actual title of your post.

#### Publish

Once you’ve completed the form, click the **Publish** button. At this time, only publishing as a ‘draft’ is allowed as you probably want to review what your post looks like before publishing it publicly.

#### Success

If your post was successful, you’ll see the following screen with the URL of your post.

![](https://cdn-images-1.medium.com/proxy/1*0vWKuqngTlx2lnert29XmQ.png)

#### Finalize on Medium

As stated, jupyter\_to\_medium only allows for publishing as a draft. To make your post public, go to your post on Medium and publish there.

![](https://cdn-images-1.medium.com/proxy/1*UiGnvY6bxjsGF0vbt60-gA.png)

#### Features

There are several features that jupyter\_to\_medium provides to ensure that your notebook appears in the

#### All images in Markdown are found and uploaded to Medium

All images in the Markdown cells, such as the five above are found and uploaded to Markdown. Medium limits the image types to png, jpeg, gif, and tiff.

#### Pandas DataFrames are converted to images

Medium does not support tables, such as those produced in output cells by pandas DataFrames. As a workaround, these tables are uploaded as images captured by the Chrome browser’s screenshot ability. In the following code cell, the [bar\_chart\_race](https://www.dexplo.org/bar_chart_race/) package is used to import a pandas DataFrame containing deaths from COVID-19 in several countries. It is embedded in the Medium post as an image.

```
import bar\_chart\_race as bcr
df = bcr.load\_dataset('covid19')
df = df.iloc[-15:-10, ::3]
df
```

![png](https://cdn-images-1.medium.com/proxy/1*zWARF2VY268WI1Cw7HlpAA.png)

#### Styled pandas DataFrames

Styled pandas DataFrames are also embedded in your post as images.

```
df.style.highlight\_max()
```

![png](https://cdn-images-1.medium.com/proxy/1*hOVKFy8RGIbNNvdt1i7olg.png)

#### Matplotlib Plots

All matplotlib plots, along with any other command that outputs an image will be safely embedded in your post.

```
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(4, 2.5), dpi=144)
df.loc['2020-04-12'].sort\_values().plot(kind='barh', ax=ax, width=.8);
```

![png](https://cdn-images-1.medium.com/proxy/1*vzrqnX5RkU8yETRksfOWJw.png)

#### Animated gifs

Even animated gifs are supported by Medium. This one created by the bar\_chart\_race function.

```
from IPython.display import Image
bcr.bar\_chart\_race(df, 'docs/images/covid19.gif', figsize=(4, 2.5))
Image(filename='docs/images/covid19.gif')
```

![png](https://cdn-images-1.medium.com/proxy/1*qOB5U2fMiFlPAx87JYajQQ.png)

#### Citing Jupyter to Medium

If you do use [jupyter\_to\_medium](https://www.dexplo.org/jupyter_to_medium), please mention in the post that you’ve used it, so that others can find out about it.

#### Master Python, Data Science and Machine Learning

Immerse yourself in my comprehensive path for mastering data science and machine learning with Python. [Purchase the All Access Pass](https://www.dexplo.org/jupyter_to_medium) to get lifetime access to all current and future courses. Some of the courses it contains:

- [Exercise Python](https://medium.com/dunder-data/selecting-subsets-of-data-in-pandas-6fcd0170be9c) A comprehensive introduction to Python (200+ pages, 100+ exercises)
- [Master Data Analysis with Python](https://www.dunderdata.com/master-data-analysis-with-python) The most comprehensive course available to learn pandas. (800+ pages and 350+ exercises)
- [Master Machine Learning with Python](https://www.dunderdata.com/master-machine-learning-with-python) A deep dive into doing machine learning with scikit-learn constantly updated to showcase the latest and greatest tools.

* * *