Curlify
Curlify is a Python library that converts `requests` request objects into equivalent cURL commands. This is particularly useful for debugging network requests by quickly generating a cURL command that can be executed directly in a terminal. The current version is 3.0.0, and it maintains an active release cadence, primarily focusing on Python version compatibility and minor enhancements.
Warnings
- breaking Python 3.6 support was dropped in `curlify` version 3.0.0. Users on Python 3.6 or older will need to upgrade their Python version or stick to `curlify<3.0.0`.
- gotcha The `curlify` function expects a `requests.PreparedRequest` object, not a raw `requests.Request` object or a `requests.Response` object. Passing the incorrect object type will result in an `AttributeError` or an incomplete cURL command.
Install
-
pip install curlify
Imports
- curlify
from curlify import curlify
Quickstart
import requests
from curlify import curlify
# Create a requests.Request object
r = requests.Request(
'GET',
'http://httpbin.org/get',
headers={'User-Agent': 'curlify-test-agent'},
params={'key': 'value'},
data={'body_key': 'body_value'}
)
# Prepare the request to get a PreparedRequest object
prepared_request = r.prepare()
# Convert the prepared request to a curl command
curl_command = curlify(prepared_request)
print(f"Generated cURL command:\n{curl_command}")