How to Get Articles from a Medium Publication

(Using Medium API Python Package)

This guide will show you how to use the Medium API to fetch and display recently published articles from a Medium publication using Python. Follow these steps to accomplish this task.

Prerequisites

Before you start, make sure you have the code medium-api package installed. You can install it using the following command:

pip install medium-api

Step-by-Step Instructions

1. Import Libraries

First, import the necessary libraries:

2. Retrieve API Key

Next, fetch your Medium API key from an environment variable:

Ensure that the RAPIDAPI_KEY environment variable is set with your Medium API key.

3. Create a Medium Object

Create an instance of the Medium class using the API key:

This object allows you to interact with the Medium API.

4. Create a Publication Object

Define the Medium publication you want to access:

Replace "98111c9905da" with the ID of the Medium publication you are interested in. The save_info=False parameter indicates that publication details are not saved locally.

5. Fetch and Display Recent Articles

Retrieve and print articles published within the last week with the following code:

This snippet fetches articles published between the current date and one week prior, then prints each article's title along with its publication date.

By following these steps, you can easily retrieve and display recent articles from a Medium publication using Python and the Medium API.

Output