How to Get a Medium Publication ID

(Using Medium API Python Package)

If you need to obtain the publication ID for a specific Medium publication, this guide will walk you through the process using the Medium API. Before you begin, ensure you have the medium-api package installed. If not, you can install it using the command:

pip install medium-api

1. Import Necessary Libraries

To start, you need to import the required libraries. You'll be using the os module to access environment variables and the Medium class from the medium-api package.

2. Retrieve the API Key from Environment Variables

The Medium API requires an API key to authenticate your requests. In this step, you'll retrieve this key from the environment variables. Make sure that your environment variable RAPIDAPI_KEY is set with your Medium API key.

3. Create a Medium Object

Next, you'll create an instance of the Medium class using the API key you retrieved. This object will allow you to interact with the Medium API.

4. Retrieve and Print the Publication ID

To get the publication ID, use the publication method of the Medium object. You'll need to specify the publication's slug, which is a unique identifier for the publication on Medium. In this example, we use the slug "towards-data-science". The publication ID will be printed to the console.

Output

Here's what you should expect as output when you run the script: