{"id":4096,"library":"mailchimp-marketing","title":"Mailchimp Marketing Python Client","description":"The `mailchimp-marketing` library is the official Python client for the Mailchimp Marketing API. It allows developers to interact with Mailchimp to manage audiences, campaigns, reports, and other marketing-related data programmatically. As of version 3.0.80, it provides a robust interface to the Mailchimp API. The library is auto-generated from a codegen tool, suggesting its release cadence is tied to updates in the underlying Mailchimp API specification.","status":"active","version":"3.0.80","language":"en","source_language":"en","source_url":"https://github.com/mailchimp/mailchimp-marketing-python","tags":["email marketing","marketing automation","Mailchimp","API client","SaaS"],"install":[{"cmd":"pip install mailchimp-marketing","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The common convention shown in official examples is to import the package as 'MailchimpMarketing' and access 'Client' from there, or use explicit 'from mailchimp_marketing.client import Client' to avoid ambiguity if other modules define a 'Client' class. The former is more prevalent in documentation.","wrong":"from mailchimp_marketing import Client\nclient = Client()","symbol":"Client","correct":"import mailchimp_marketing as MailchimpMarketing\nclient = MailchimpMarketing.Client()"},{"symbol":"ApiClient.ApiException","correct":"from mailchimp_marketing.api_client import ApiClient\ntry: ... except ApiClient.ApiException as e: ..."}],"quickstart":{"code":"import os\nimport mailchimp_marketing as MailchimpMarketing\nfrom mailchimp_marketing.api_client import ApiClient\n\n# It's recommended to store your API key and server prefix as environment variables.\n# The server prefix (e.g., 'us1', 'us19') is typically the last part of your API key (e.g., 'YOUR_KEY-us19').\n\napi_key = os.environ.get(\"MAILCHIMP_API_KEY\", \"\")\nserver_prefix = os.environ.get(\"MAILCHIMP_SERVER_PREFIX\", \"\")\n\n# Fallback to extract server prefix from API key if not explicitly set\nif not server_prefix and '-' in api_key:\n    server_prefix = api_key.split('-')[-1]\n\nif not api_key:\n    print(\"ERROR: MAILCHIMP_API_KEY environment variable not set.\")\n    print(\"Please set it to your Mailchimp API key. Example: export MAILCHIMP_API_KEY='yourkey-us1'\")\n    exit(1)\n\nif not server_prefix:\n    print(\"ERROR: MAILCHIMP_SERVER_PREFIX environment variable not set and could not be extracted from API key.\")\n    print(\"Please set it to your Mailchimp server prefix (e.g., 'us1').\")\n    exit(1)\n\n# Initialize the Mailchimp Marketing Client\nclient = MailchimpMarketing.Client()\nclient.set_config({\n    \"api_key\": api_key,\n    \"server\": server_prefix\n})\n\ntry:\n    # Example: Get basic account information (ping the API)\n    response = client.ping.get()\n    print(\"Successfully connected to Mailchimp API. Health status:\")\n    print(response)\n\n    # Example: List all audiences (uncomment to run)\n    # print(\"\\nFetching audiences...\")\n    # audiences_response = client.lists.get_all_lists()\n    # if 'lists' in audiences_response:\n    #     for list_item in audiences_response['lists']:\n    #         print(f\"  - Name: {list_item.get('name')}, ID: {list_item.get('id')}\")\n    # else:\n    #     print(\"No audiences found or unexpected response.\")\n\nexcept ApiClient.ApiException as e:\n    print(f\"Error calling Mailchimp API: {e}\")\n    print(f\"Status: {e.status}, Reason: {e.reason}, Body: {e.body}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to initialize the Mailchimp client using API key and server prefix from environment variables and perform a basic API call (ping). It also includes a commented-out example for listing audiences. Ensure `MAILCHIMP_API_KEY` and `MAILCHIMP_SERVER_PREFIX` are set in your environment."},"warnings":[{"fix":"Consolidate contacts into a single audience and use Mailchimp's built-in tags and groups for effective segmentation. Regularly clean your list to remove inactive or unsubscribed contacts.","message":"Mailchimp billing is based on the total number of contacts across *all* audiences in your account. Using multiple audiences for segmentation can lead to duplicate contacts, increased costs, and management complexity. It's generally recommended to use a single master audience with tags and groups for segmentation instead.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If your workflows depend on email automation, evaluate Mailchimp's paid plans or consider migrating to an email marketing platform that offers automation features within your budget.","message":"As of June 1, 2025, Mailchimp has discontinued the 'Classic Automation Builder' and removed email automation features entirely from its Free plan. Users on the Free plan who relied on automations (e.g., welcome sequences) will need to upgrade to a paid plan or switch to an alternative service.","severity":"breaking","affected_versions":"Free plan users as of June 1, 2025"},{"fix":"Ensure both `api_key` and `server` are correctly configured when initializing the client. The server prefix can typically be extracted from your API key (the part after the hyphen).","message":"All Mailchimp API requests require both an API key and a server prefix (e.g., 'us1', 'us19'). The server prefix is often embedded in your API key (e.g., 'YOUR_KEY-us19'). Incorrectly providing or omitting the server prefix will result in authentication failures.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement proper pagination and rate-limiting strategies in your application. For bulk operations, consider using Mailchimp's Batch endpoint where available.","message":"The Mailchimp Marketing API enforces rate limits (e.g., up to 10 simultaneous connections), and excessive concurrent calls may result in HTTP 429 (Too Many Requests) or 403 errors. Large or long-running requests have a 120-second timeout.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}