Mailchimp3 Python Client

3.0.21 · active · verified Thu Apr 16

mailchimp3 is a Python client library for interacting with version 3 of the Mailchimp API. It provides a straightforward interface to manage contacts, lists, campaigns, and other Mailchimp resources. The library is currently at version 3.0.21 and maintains an active development status with updates for API changes and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `MailChimp` client using an API key and an optional username, and then how to fetch all audience lists. It's best practice to use environment variables for sensitive credentials.

import os
from mailchimp3 import MailChimp

# It's recommended to store API keys and usernames in environment variables
api_key = os.environ.get('MAILCHIMP_API_KEY', 'YOUR_MAILCHIMP_API_KEY')
username = os.environ.get('MAILCHIMP_USERNAME', 'YOUR_MAILCHIMP_USERNAME') # Optional for basic auth

# Initialize the MailChimp client
# As of v2.1.0, arguments are mc_api and mc_user (username is optional)
client = MailChimp(mc_api=api_key, mc_user=username)

# Example: Fetch all lists
try:
    lists = client.lists.all()
    print("Successfully fetched lists:")
    for l in lists['lists']:
        print(f"  - {l['name']} (ID: {l['id']})")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →