How to get Medium stats data and make your own visualizations

I started to write programming & data related articles in Medium recently. Just as a new curious user to Medium, I frequently visit to check how many readers has read my posts. Although those numbers rarely change, but these numbers are really what I care, at least for current several days. Since it means something for me, I want to keep trace of those numbers (especially the change trending)

But soon, I learned although Medium has API:

But its API is quite limited, mainly used to publish articles to Medium. But there is no official Medium Stats API. After more research, I found an already Archived project:

The most useful thing I learned is: when you use HTTP Clients to access, if you set “SID” & “UID” inside cookie, then you can get data successfully (Although the return data is HTML, but it is very easy to use regex to extract the real stats data in JSON format), Great!

First, just visit by web browser, like Chrome. Then, open Chrome’s developer tool, inside “Network” tab, find any request, and look up the “sid” & “uid” inside cookie HTTP Header. (keep those in secret), then I wrote the following Python Script to fetch my article data, and save them into Apache Parquet format.

After python script run successfully, I have save those data into my local file. I can add some additional logic to merge those files together to keep all the data change histories.

Since data is ready, Let’s make some plots. I’d like to use open source tools to do this job. Streamlit is an amazing tool, by using it, I can turn small number of python lines into a fully workable web application! The Python script for my web app is as following:

I personally like to use altair (which wraps Vega-Lite) for visualization, but streamlit also support several alternatives. Finally, I can have my own dashboard!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store