How to Search Publications on Medium

(Using Medium API Python Package)

If you're interested in finding publications related to specific topics on Medium, you can automate this process using the Medium API with Python. This guide will walk you through the steps needed to search for publications using this API.

Prerequisite

Before you begin, ensure you have the code medium-api package installed. You can install it using pip:

pip install medium-api

Step-by-Step Guide

1. Import Necessary Libraries

Start by importing the required libraries. You'll need the code os library to access environment variables and the code Medium class from the code medium_api package to interact with the Medium API.

2. Get Your API Key

Retrieve your Medium API key from the environment. This key is necessary for authenticating your requests. Make sure you have set this environment variable appropriately in your development environment.

3. Create a Medium Object

Instantiate the code Medium object using your API key. This object will be used to interact with the Medium API.

4. Search for Publications

Use the code search_publications method to find publications related to your query. In this example, we're searching for publications related to "artificial intelligence". You can modify the code query parameter to search for other topics. The code save_info parameter can be set to code True if you want to store additional information about the publications, but be cautious as this may consume more API calls.

5. Display Results

Loop through the list of publications returned by the search and print each publication's name and the number of followers it has. This helps you understand the reach and influence of the publications related to your search query.

Output

To see the output of running the script, refer to the following gist: