API Reference

PostMonkey

class postmonkey.PostMonkey(apikey='', endpoint=None, datacenter=None, timeout=None, **params)

apikey

The API key for your MailChimp account, obtained from MailChimp.

endpoint

The URL used for API calls. Will be inferred from your API key unless you specifically override it (not recommended except for testing).

datacenter

The MailChimp supplied data center for your account. Will be inferred from your API key unless you specifically override it. Cannot be accessed or modified after initialization.

params

Any extra keyword arguments supplied on initialization will be made available in a dict via this attribute. Only include parameters that should be used on each and every API call. For instance, if you want to add a subscription form to your website, you can parameterize the list’s ID.

postrequest

Defaults to requests.post, and should not be changed except for testing or if you have a really good reason. If you do override it, you must supply a function that takes a URL, a JSON encoded payload, a dict of HTTP headers, and optionally a timeout (in seconds). Must return a response object with a text attribute containing valid JSON.
postmonkey.postmonkey_from_settings(settings)

Factory method that takes a dict, finds keys prefixed with ‘postmonkey.’, and uses them to create a new PostMonkey instance. Intended for use with console scripts or web frameworks that load config file data into a dict.

Exceptions

exception postmonkey.exceptions.DeserializationError(obj)

Raised if MailChimp responds with anything other than valid JSON. PostMonkey uses MailChimp’s JSON API exclusively so it is unlikely that this will be raised. The response that caused the error is made available via the obj attribute.

exception postmonkey.exceptions.MailChimpException(code, error)

If MailChimp returns an exception code as part of their response, this exception will be raised. Contains the unmodified code (int) and error (unicode) attributes returned by MailChimp.

exception postmonkey.exceptions.PostRequestError(exc)

If any exception is made during the POST request to MailChimp’s server, PostRequestError will be raised. It wraps the underlying exception object and makes it available via the exc attribute.

exception postmonkey.exceptions.SerializationError(obj)

Raised if a method call contains parameters that cannot be serialized to JSON. The object that caused the error is made available via the obj attribute.