Klaviyo charges customers based on the number of active profiles, which can add up quickly. Often, email marketers use Klaviyo for transactional emails that require a user to be subscribed to a list, but once the initial transaction completes, there may be no need to keep these profiles. This utility app helps remove unnecessary profiles from Klaviyo lists, keeping only those profiles actively engaged in your marketing efforts and reducing your active profile count.
This app consists of two parts:
dedupe.py
– Identifies profiles present in transactional (master) lists but absent from marketing (opt-in) lists.main.py
– Deletes profiles found bydedupe.py
from Klaviyo to manage active profiles more efficiently.
- Python 3.x installed on your system
- A Klaviyo API key (with permissions to access and delete profiles)
- List IDs for both your transactional and marketing lists
-
Clone this repository and navigate to the project directory:
git clone <repository-url> cd klaviyo-dedupe-delete
-
Install Required Libraries: Install necessary dependencies using
pip
:pip install -r requirements.txt
-
Create a
.env
file:- In the root of the project directory, create a
.env
file to securely store your Klaviyo API key. - Add the following line to your
.env
file, replacingYOUR_KLAVIYO_API_KEY
with your actual Klaviyo API key.KLAVIYO_API_KEY=YOUR_KLAVIYO_API_KEY
- In the root of the project directory, create a
-
Edit the Lists in
dedupe.py
: Opendedupe.py
and add the list IDs for your master (transactional) and marketing (opt-in) lists:# List IDs master_lists = ["YOUR_MASTER_LIST_ID_1", "YOUR_MASTER_LIST_ID_2"] marketing_lists = ["YOUR_MARKETING_LIST_ID_1", "YOUR_MARKETING_LIST_ID_2", ...]
- Purpose:
dedupe.py
generates a CSV with profiles in your transactional lists that are not present in your marketing lists. - Usage:
- Run
dedupe.py
with:python dedupe.py
- This will create a CSV file named
unique_master_profiles.csv
in your project directory. - The CSV will contain profile IDs from your master lists that are not in any marketing list.
- Run
- Purpose:
main.py
deletes profiles from Klaviyo that are listed in theunique_master_profiles.csv
file generated bydedupe.py
. - Usage:
- Important: Consider working on a small subset of your
unique_master_profiles.csv
to ensure the deletion process works as expected. - Run
main.py
with:python main.py
- The script will:
- Process each profile ID from the CSV, initiating a deletion request with Klaviyo’s API.
- Remove successfully deleted IDs from the CSV file after each request, allowing you to stop and resume the process safely.
- Important: Consider working on a small subset of your
- Start with a Subset: Especially if this is your first time running this utility, test with a subset of profiles by creating a smaller CSV file from
unique_master_profiles.csv
. - Monitor the Script’s Output: Each successful deletion will print the profile ID to the console, while any failures will also be logged.
- Rate Limits: Klaviyo's API allows up to 60 profile deletions per minute, so
main.py
includes a small delay between each request to avoid hitting rate limits. - Real-Time File Updates: After each profile is successfully deleted,
main.py
immediately removes it from the CSV, so the file always reflects the list of remaining profiles.
- Profiles Not Deleting in Real-Time: If the CSV file does not update in real-time, ensure you are using the latest version of
main.py
which incorporates immediate file writing after each deletion. - Klaviyo API Errors: If you see errors related to missing attributes, double-check your Klaviyo API key and ensure the API key has the required permissions.
This utility is designed to help email marketers effectively manage their Klaviyo profiles, reduce unnecessary active profiles, and avoid unnecessary charges.