FormatterHQ

cURL to Python requests Converter

Paste a curl command and get idiomatic Python code for the requests library, with headers, query params, JSON bodies, files, cookies and auth as Python dicts.

Input SHELL
Output PYTHON
Ready.

How to use the cURL to Python Requests

  1. Copy a curl command from API docs or use Copy as cURL in your browser’s network panel.
  2. Paste it into the input editor.
  3. Review the generated Python code, which uses the requests library.
  4. Install requests if needed (pip install requests) and run the script.

Readable Python from any curl command

The requests library is the most popular way to call HTTP APIs from Python, and its keyword arguments map neatly onto curl's options. This curl to Python converter produces idiomatic code: headers, query parameters, cookies and JSON bodies become Python dictionaries instead of long encoded strings, so the request is easy to read and modify.

Example

curl -X POST 'https://api.example.com/v1/orders?notify=true' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -d '{"sku":"LAMP-01","qty":2}' \
  --max-time 30
import requests

headers = {
    'Authorization': 'Bearer YOUR_API_TOKEN',
}

params = {
    'notify': 'true',
}

json_data = {
    'sku': 'LAMP-01',
    'qty': 2,
}

response = requests.post('https://api.example.com/v1/orders',
    headers=headers,
    params=params,
    json=json_data,
    allow_redirects=False,
    timeout=30,
)

print(response.status_code)
print(response.text)

Notice that the Content-Type: application/json header disappears: passing json= makes requests serialize the body and set that header automatically.

How the conversion works

  • Query string – parameters in the URL are moved into a params dict.
  • JSON bodies – parsed and written as Python literals (True, False, None) for json=.
  • Form data – URL-encoded bodies become a data dict; -F fields become data and files with open(path, 'rb').
  • Cookies – a Cookie header or -b value becomes a cookies dict.
  • Auth – -u user:pass becomes auth=('user', 'pass').
  • Redirects – curl does not follow redirects unless you pass -L, while requests does. The converter adds allow_redirects=False so behavior matches; remove it or add -L to follow redirects.
  • TLS and proxies – -k becomes verify=False (for testing only) and -x becomes a proxies dict.
  • Timeouts – --connect-timeout and -m become timeout=(connect, total).

Supported curl options

curl optionMeaning
-X, --requestHTTP method (GET, POST, PUT, PATCH, DELETE…)
-H, --headerRequest headers
-d, --data, --data-raw, --data-binary, --data-urlencodeRequest body; implies POST
--jsonJSON body with Content-Type and Accept headers
-F, --formMultipart form fields and file uploads
-u, --user and --oauth2-bearerBasic and bearer authentication
-b, --cookie, -A, -eCookies, user agent and referer
-G, --getSend -d data as query string
-L, -k, -m, -x, -I, -TFollow redirects, skip TLS checks, timeout, proxy, HEAD request, upload file

Line continuations (\), single and double quotes are parsed like a Unix shell. Options that only affect curl's own output, such as -s, -v or -o, are ignored silently; any other unsupported option is listed as a comment at the top of the generated code, so nothing is dropped without notice.

Next steps

  • Run the script with Python 3 in a virtual environment so the requests package does not conflict with system packages.
  • Always keep a timeout; without one, requests can wait indefinitely.
  • Call response.raise_for_status() to turn HTTP errors into exceptions, and response.json() to parse JSON responses.
  • Load tokens from environment variables (os.environ['API_TOKEN']) instead of committing them.
  • For many requests to the same host, use a requests.Session() to reuse connections.

Need a different language? Use cURL to PHP or cURL to JavaScript. To inspect the response format first, send the request with the API tester. Conversion happens locally in your browser.

Frequently asked questions

Do I need to install anything to run the code?
Yes, the requests package. Install it with pip install requests. It supports all maintained Python 3 versions.
Why is allow_redirects=False added?
curl does not follow redirects unless you use -L, but requests follows them by default. The flag keeps the Python code’s behavior identical to your curl command.
Why did the Content-Type header disappear?
When the body is JSON, the code passes it with json=, and requests sets the application/json Content-Type header automatically.
Can it convert file uploads?
Yes. -F "file=@report.pdf" becomes a files dict that opens the file in binary mode, which requests sends as multipart/form-data.
Is verify=False safe?
Only for local testing against self-signed certificates. It disables certificate checks and exposes the connection to interception, so never use it in production.

Last updated October 3, 2026

Related tools

cURL to Axios (Node.js) Converter Convert curl commands to Node.js axios requests with params, headers, JSON data, auth, form-data uploads and timeouts. cURL to C# Converter Convert curl commands to C# HttpClient code for .NET with headers, content types, basic auth, multipart and TLS options. cURL to Go Converter Convert curl commands into Go code using net/http — method, headers, JSON or form body, basic auth, timeouts and multipart uploads. cURL to PHP Guzzle Converter Convert curl commands to PHP Guzzle requests using json, form_params, multipart, query and auth options. cURL to Java Converter Convert curl commands to Java 11+ java.net.http.HttpClient code with headers, body, redirects and timeouts. cURL to JavaScript Fetch Convert curl commands into JavaScript fetch() code with method, headers, JSON body, form data, basic auth and timeouts. cURL to Rust Converter Convert curl commands to Rust using the reqwest crate, with JSON bodies via serde_json, headers, auth and timeouts. Date & Time Calculator Calculate the difference between two dates or add/subtract days, weeks, months and years from a date. Docker Run to Docker Compose Convert one or more docker run commands into a docker-compose.yml: ports, volumes, env, restart, networks, healthchecks and more. File Type Checker Find out what a file really is from its content, not its name. Detects 150+ formats and warns when the extension does not match. HTTP Status Codes Searchable list of the HTTP status codes in use, from 100 to 511, with a plain explanation of when each response is used. JWT Decoder Decode a JSON Web Token to inspect its header, payload claims and expiry time, and verify its signature with your key. Runs locally.