How to Get Top Feeds from Medium

(Using Medium API Python Package)

In this guide, we'll walk through how to use the Medium API to fetch and display the top articles from Medium related to a specific topic. For this task, we will use the medium-api Python package.

Prerequisite

Before starting, make sure you have the medium-api package installed. You can install it using pip:

pip install medium-api

Step-by-Step Guide

1. Import Required Libraries

First, you'll need to import the necessary libraries. In this case, we use os for environment variable access and Medium from the medium-api package.

2. Retrieve the API Key

Next, you need to retrieve your API key from the environment variables. This key is essential for authenticating your requests to the Medium API.

3. Create a Medium Object

With the API key in hand, create an instance of the Medium class. This object will be used to interact with the Medium API.

4. Fetch Top Feeds

Now, create a TopFeeds object specifying the tag and mode. In this example, we are fetching the latest articles related to "data-science".

5. Retrieve and Print Articles

Fetch the articles using the fetch_articles method. Then, iterate over the articles and print their titles.

Output

The output will be a list of titles of the top articles related to "data-science". You can view a sample output using the following gist:

With just a few steps, you can easily fetch and display top Medium articles on a specific topic using the medium-api Python package. By following this guide, you should be able to integrate Medium feeds into your own applications or simply gather interesting content for your personal use.