How to Get Root Tags from Medium

(Using Medium API Python Package)

In this guide, we'll walk through a Python script that retrieves the root tags (top-level tags) from the Medium platform using the medium-api library. This can be useful for developers looking to explore or interact with Medium's tagging system programmatically.

Prerequisites

Before you start, ensure you have the medium-api library installed. You can install it using pip:

pip install medium-api

Step-by-Step Guide

1. Import Libraries

First, we need to import the required libraries:

Here, os is used to access environment variables, and Medium is the class from the medium-api library that will allow us to interact with Medium's API.

2. Get the API Key

To authenticate with Medium's API, you'll need an API key. The script retrieves this key from the environment variables:

Ensure that your API key is set in your environment variables under the name RAPIDAPI_KEY. If you don't have an API key, you'll need to obtain one from Medium or the service you're using.

3. Create a Medium Object

With the API key in hand, you can create an instance of the Medium class:

This object will allow you to make requests to the Medium API.

4. Retrieve Root Tags

Now, you can use the Medium object to get the root tags from Medium:

This method call retrieves a list of top-level tags from the Medium platform.

5. Print the Root Tags

Finally, you can print out the tags to see the result:

This loop iterates through the list of tags and prints each one to the console.

Output

By following these steps, you can easily fetch and display the root tags from Medium using Python. This script provides a simple yet effective way to interact with Medium's tagging system.