Giter VIP home page Giter VIP logo

postmonkey's Introduction

PostMonkey is a simple Python (2.6+) wrapper for MailChimp's API version 1.3.

Features

  1. 100% unit test and code coverage
  2. Connections handled by Requests
  3. Configurable timeout
  4. Simple Exceptions

Basic Usage

Once you create a PostMonkey instance with your MailChimp API key, you can use it to call MailChimp's API methods directly:

    from postmonkey import PostMonkey
    pm = PostMonkey('your_api_key')
    pm.ping() # returns u"Everything's Chimpy!"

If the MailChimp method call accepts parameters, you can supply them in the form of keyword arguments. See Examples for common use cases, and refer to the MailChimp API v1.3 official documentation for a complete list of method calls, parameters, and response objects.

MailChimp has established guidelines/limits for API usage, so please refer to their FAQ for information.

Note: it is the caller's responsibility to supply valid method names and any required parameters. If MailChimp receives an invalid request, PostMonkey will raise a postmonkey.exceptions.MailChimpException containing the error code and message. See MailChimp API v1.3 - Exceptions for additional details.

Examples

Create a new PostMonkey instance with a 10 second timeout for requests:

    from postmonkey import PostMonkey
    pm = PostMonkey('your_api_key', timeout=10)

Get the IDs for your campaign lists:

    lists = pm.lists()

    # print the ID and name of each list
    for list in lists['data']:
        print list['id'], list['name']

Subscribe "emailaddress" to list ID 5:

    pm.listSubscribe(id=5, email_address="emailaddress")

Catch an exception returned by MailChimp (invalid list ID):

    from postmonkey import MailChimpException
    try:
        pm.listSubscribe(id=42, email_address="emailaddress")
    except MailChimpException, e:
        print e.code  # 200
        print e.error # u'Invalid MailChimp List ID: 42'

Get campaign data for all "sent" campaigns:

    campaigns = pm.campaigns(filters=[{'status': 'sent'}])

    # print the name and count of emails sent for each campaign
    for c in campaigns['data']:
        print c['title'], c['emails_sent']

postmonkey's People

Contributors

ericrasmussen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.