How to Get Articles from a Medium List

(Using Medium API Python Package)

If you need to fetch articles from a specific Medium list using Python, you can achieve this with the medium-api library. This guide will walk you through the steps needed to get all the articles from a Medium list and print their titles. Before diving into the code, ensure you have the medium-api library installed with:

pip install medium-api

Let's break down the process:

1. Import Required Libraries

First, you need to import the necessary libraries. You’ll use os to handle environment variables and Medium from medium_api to interact with Medium's API.

2. Retrieve the API Key

The API key is essential for authenticating your requests. Ensure that your Medium API key is stored in your environment variables under the name RAPIDAPI_KEY. Retrieve it using the os.getenv() function:

3. Create a Medium Object

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

4. Create and Use a Medium List Object

Create a MediumList object by passing the ID of the Medium list you want to access. Then, use the fetch_articles() method to retrieve all articles from that list.

5. Display the Titles of the Articles

Finally, loop through the articles retrieved from the list and print their titles.

Summary

This code snippet demonstrates how to use the medium-api library to access articles from a Medium list. You first import the necessary libraries, retrieve your API key, and create a Medium object. After fetching the articles from your desired list, you simply iterate through them to print their titles.

With these steps, you should be able to pull articles from any Medium list with ease.