import uuid


def jsonrpc_request(method, params, call_id=None):
    """
    Marshal an RPC request in JSON-RPC 2.0 format.

    See http://www.jsonrpc.org/specification for details.

    :param method: remote method to invoke
    :param params: parameters to remote method
    :param call_id: value of JSON-RPC 'id' parameter

    :returns: dictionary suitable for passing to json.dumps() to get a
              serialized JSON-RPC request
    """
    # JSON-RPC requires an 'id' parameter in order to receive a response,
    # and that parameter has to be unique for every call made by that
    # client.
    if call_id is None:
        call_id = str(uuid.uuid4())

    return {'jsonrpc': '2.0',  # magic value
            'method': method,
            'params': params,
            'id': call_id}