How to Get Recommended Feed Articles from Medium by Tag

(Using Medium API Python Package)

In this guide, we'll walk through how to retrieve recommended feed articles from Medium using the Medium API in Python. By following these steps, you'll be able to fetch and display articles based on a specific tag. Before you start, make sure you have the medium-api library installed. If not, you can install it using the following command:

pip install medium-api

Let's break down the code and understand each part.

1. Import Required Libraries

First, we need to import the necessary libraries. Here, we'll use the os library to handle environment variables and the Medium class from the medium_api library to interact with Medium's API.

2. Set Up API Key

Next, we retrieve the API key from the environment variables. The API key is necessary to authenticate and make requests to Medium's API.

3. Create a Medium Object

With the API key, we can now create an instance of the Medium class. This object will be used to interact with Medium's API.

4. Fetch Recommended Feed Articles

To get the recommended feed, we create a RecommendedFeed object by specifying a tag (e.g., "artificial-intelligence") and the number of articles we want to fetch (e.g., 15). After creating the object, we call the fetch_articles() method to retrieve the articles.

5. Display Article Titles

Finally, we loop through the fetched articles and print their titles.

Output

The output of the script will display the titles of the recommended articles. For example:

By following these steps, you will be able to fetch and display recommended articles from Medium based on a specific tag. Feel free to adjust the tag and count parameters according to your needs.