Skip to main content
Prerequisite You should have an API key from Plausible Analytics and have it stored in a .env file.

Introduction

This guide demonstrates how to set up a Python script to fetch website analytics data from Plausible Analytics using the Plausible API. You’ll learn how to install the necessary library, set up your environment, and create a simple script to fetch and display analytics data.
fetch_plausible_analytics.py

Setup

Step 1: Install Required Packages

First, install the necessary packages using pip:

Step 2: Create a .env File

Create a .env file in the project root with your Plausible API key:

Step 3: Create the Python Script

Create a Python script named fetch_plausible_analytics.py with the following content:
fetch_plausible_analytics.py

Step 4: Run the Script

Ensure you have the .env file in the same directory as the script. Then, execute the script:

Conclusion

You have successfully set up a Python script to fetch website analytics data from Plausible Analytics using the Plausible API! This guide provided a basic example to get you started. You can now expand on this by customizing the data parameters and handling different scenarios.