python-astrid /

import requests
import time
import hashlib

from urllib import urlencode

class AstridAPI(object):
    '''Class to connect to astrid and issue requests to a specific
    user's account.'''

    def __init__(self, conf):
        '''Initialize the API. conf is a dictionary containing:
            "apikey": "<astrid api key>",
            "apisecret": "<astrid api secret>",
            "email": "", # your astrid e-mail
            "password": "<astrid password>"
        The apikey and secret can come from
        assuming you have an account.

        Automatically signs in the user associated with the username and
        password provided in the configuration dictionary. The token received
        from signin is stored
        self.server = ''
        self.astrid_api_version = 7
        self.apikey = conf['apikey']
        self.apisecret = conf['apisecret']
            self.token = self.send_request("user_signin",
        except KeyError:
            raise AttributeError("Unable to sign into astrid. Ensure your "
                "api key, api secret, email, and password are correct.")

    def send_request(self, method, **params):
        '''Send a request to the astrid API. The available methods and their
        parameters are described in

        This method does the necessary work to create an astrid signature line
        as required by the API. It then issues the request in the format Astrid

        :param method: the method name to call in the Astrid API
        :param params: keyword arguments mapping parameters to values as
            required by the /method/
        :return: json decoded response of your Astrid API request
        :rtype: dict
        signature = []
        params['app_id'] = self.apikey
        params['time'] = time.time()
        if hasattr(self, 'token'):
            params['token'] = self.token
        for param in sorted(params):
            value = params[param]
            if isinstance(value, list):
                signature.extend([("%s[]%s" % (param, v)) for v in value])
                signature.append("%s%s" % (param, value))
        sig = "%s%s%s" % (method, "".join(signature), self.apisecret)
        sig = hashlib.md5(sig).hexdigest()
        params['sig'] = sig

        url = "%s/api/%s/%s?%s" % (

        return, data=params).json