How to Get Recommended Medium Users by Tag

(Using Medium API Python Package)

This guide walks you through a simple Python program to fetch recommended users for a particular tag from Medium, using the Medium API.

Prerequisite

Before you start, make sure to install the Medium API package by running the following command in your terminal:

pip install medium-api

Step-by-Step Guide

1. Import Required Libraries

To begin, you need to import the necessary Python libraries. The

library helps you retrieve environment variables, and is the class from the Medium API package that allows you to interact with the Medium platform.

2. Retrieve Your Medium API Key

The next step is to securely retrieve your API key from the environment. For this, make sure you have set your

RAPIDAPI_KEY as an environment variable. The following code fetches that key:

Ensure that your API key is stored in your environment variable under the name

RAPIDAPI_KEY. This keeps your API key safe and avoids hard-coding sensitive information.

3. Create a Medium Object

Now that you have your API key, create a

Medium object, which is essential for making any API requests to Medium.

This object allows you to interact with Medium's API and perform various operations, such as fetching articles, users, or recommendations.

4. Get Recommended Users by Tag

You can now retrieve the recommended users for a specific tag. In this example, we use the tag

"artificial-intelligence" to get users who are relevant in that domain.

This fetches user recommendations based on the tag you specify. You can replace

"artificial-intelligence" with any tag you are interested in.

5. Display Recommended Users

Finally, we'll retrieve and display the recommended users. The

fetch_users() method is used to get details about the users, and a loop is used to print the full name and username of each recommended user.

This outputs the recommended users' names and usernames for the given tag. For example:

Conclusion

By following this guide, you can easily fetch and display recommended users for any tag on Medium using Python. This is particularly useful for discovering influencers or relevant authors within a specific domain.