Before you begin, you need to get your API key and list ID by logging in to Mailchimp.
To get the API key, go to Accounts> Extras and generate the API key. To get the list identifier, go to List> My list> Settings> List name and default values.
Then make sure you install the python mailchimp package:
pip install mailchimp
Finally:
import mailchimp API_KEY = 'my-api-key' LIST_ID = 'my-list-id' api = mailchimp.Mailchimp(API_KEY) api.lists.subscribe(LIST_ID, {'email': ' email@example.com '})
source share