How to Get Books Published by a Medium User

(Using Medium API Python Package)

In this guide, we'll walk through how to retrieve all the books published by a verified Medium user using the Medium API and Python. You'll need the medium-api library, which can be installed by running:

pip install medium-api

Step 1: Import the Required Libraries

To start, import the necessary libraries. You'll be using os to retrieve environment variables and medium_api to interact with the Medium API.

Step 2: Retrieve Your API Key

You will need an API key to authenticate your requests. The API key should be stored in your environment variables for security reasons. The following line of code retrieves the API key from the environment:

Make sure to replace RAPIDAPI_KEY with the actual environment variable name where your Medium API key is stored.

Step 3: Create a Medium Object

Next, create a Medium object using your API key. This object will allow you to interact with the Medium API.

Step 4: Fetch the User Object

To retrieve information about a user (in this case, their books), create a user object using the Medium API by passing the username of the Medium user.

In this example, the username is anangsha, but you can replace it with any valid Medium username.

Step 5: Iterate Through the User's Published Books

Finally, loop through the books published by the user and print out their details, such as the book's name, description, authors, URLs, publication date, and cover image.

This code prints the information about each book in a readable format.

Output

Below is a sample output showing the details of the books retrieved:

Conclusion

By following these steps, you can easily retrieve and display all the books published by a specific Medium user using the Medium API in Python. This is useful if you want to gather and display user publications programmatically.