def to_curl_command(request):
    """ Convert a requests preparred request to curl command
    """
    command = "curl -i -X {method}{headers} -d '{data}' '{uri}'"
    method = request.method
    uri = request.url
    data = request.body
    if data is None:
        data = ''
    headers = ["{0}: '{1}'".format(k, v) for k, v in request.headers.items()]
    headers = " -H ".join(headers)
    if headers:
        headers = " -H {} ".format(headers)
    return command.format(method=method, headers=headers, data=data, uri=uri)