def to_query(obj, ns=None):
    if isinstance(obj, dict):
        pairs = sum((to_query(v, six.u("{0}[{1}]".format(ns, k)) if ns else k)
                     for k, v in six.iteritems(obj)), [])
        if ns:
            return pairs
        return "&".join(six.u("{0}={1}".format(*p)) for p in sorted(pairs))
    elif isinstance(obj, (list, tuple)):
        return sum((to_query(v, six.u("{0}[]".format(ns))) for v in obj), [])
    else:
        return [(percent_encode(six.text_type(ns)), percent_encode(six.text_type(obj)))]
Create a query string from a list or dictionary
dataset/ETHPy150Open gocardless/gocardless-python/gocardless/utils.py/to_query