How to Get Medium User Information

(Using Medium API Python Package)

In this guide, you'll learn how to retrieve detailed information about a Medium user using the Medium API in Python. This is useful if you want to analyze user profiles or retrieve specific data about a Medium user, such as their bio, the number of articles they've written, or their social media links.

Here's the full code if you'd like to check it out directly:

Prerequisite:

Install the required package by running the following command:

pip install medium-api

Steps to Retrieve Medium User Information:

1. Import Necessary Libraries:

First, import the required libraries. You'll need the os module to access environment variables, and the Medium class from the medium_api package to interact with the Medium API.

2. Set Up API Key:

Make sure your Medium API key is stored in an environment variable named RAPIDAPI_KEY. The code retrieves the API key from the environment using the os.getenv() function:

3. Create a Medium Object:

Use the API key to create an instance of the Medium class. This object will allow you to interact with the Medium API.

4. Fetch User Information:

Now, create a user object by passing the Medium username to the user() method. This retrieves the profile information of the specified user.

5. Display User Information:

Once you have the user object, you can access various attributes like the user's full name, bio, profile image, and much more. Here's how to print the key information:

Output:

After running the script, the user details will be displayed as shown below:

Conclusion:

By following the steps above, you can easily retrieve and display detailed information about any Medium user using Python. This process is straightforward and can be used to analyze user data or even build applications that interact with Medium user profiles.