Skip to content
My Tiny Utils

Search tools

Type to find a tool, then press Enter to open it.

cURL to Python

Convert cURL commands to Python requests code instantly. Handles headers, cookies, query params, JSON and form bodies, file uploads, auth, proxies, and timeouts.

Processed locally in your browser — nothing is uploaded.

cURL to Python

0 characters

Python requests

Output appears here…

About cURL to Python

Paste a cURL command — from Chrome or Firefox DevTools ("Copy as cURL"), an API's documentation, or a shell script — and get the same request written with Python's requests library. The command is read by the same shell-style tokenizer as the cURL to Fetch and cURL to Axios converters, so quoting, escapes, and backslash line continuations behave the way they do in your terminal.

The code is written the way you would write it by hand:

  • Query strings become params, cookies from -b or a Cookie header become cookies, and the remaining headers a headers dict.
  • JSON bodies become a json= dict, with true, false, and null turned into True, False, and None. Form data from -d becomes a data dict, and -F fields become files, including curl's ;type= and ;filename= options.
  • Transport flags carry over: -u becomes an auth tuple, -k becomes verify=False, --cacert a verify path, -m and --connect-timeout a timeout, -x a proxies dict, and -o writes the response to that file.

Nothing is rewritten if that would change what goes over the wire. requests encodes a space in a query string or form as +, so a value curl sends as %20 is kept in the URL or body exactly as written rather than split into a dict. A body with non-ASCII text is sent as UTF-8 bytes, because requests would otherwise encode a plain string as Latin-1 and fail.

Common uses

  • Turn a request from your browser's DevTools into a Python script for scraping, testing, or automation
  • Convert cURL examples from API documentation into working Python code
  • Move a shell script's curl calls into a Python project or a Jupyter notebook

Example

Input

curl 'https://api.example.com/users?page=2' -H 'Authorization: Bearer YOUR_TOKEN' -b 'session=abc123'

Output

import requests

params = {
    "page": "2",
}

cookies = {
    "session": "abc123",
}

headers = {
    "Authorization": "Bearer YOUR_TOKEN",
}

response = requests.get(
    "https://api.example.com/users",
    params=params,
    cookies=cookies,
    headers=headers,
)

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

Limitations

  • @file references in -d can't be read from a pasted command; paste the file's contents instead. -F uploads become open() calls you point at the real file
  • requests follows redirects for every method but HEAD, even without -L; pass allow_redirects=False if you rely on curl's default of not following them
  • --max-time limits curl's whole transfer, while requests' timeout limits connecting and each read, so a slow download can run longer
  • requests speaks HTTP/1.1 only, so --http2 is dropped, and options with no equivalent, like --retry, are listed as notes

Frequently asked questions

How do I convert a cURL command to Python requests?

Paste the command into the box above and the Python appears as you type. Headers become a headers dict, the query string a params dict, cookies a cookies dict, and the body json=, data=, or files= depending on its type, ending in a requests.get(), requests.post(), or other call for the command's method.

Should I use json= or data= for a cURL -d body?

Use json= when the body is JSON: requests serializes the dict and sets Content-Type: application/json for you. Use data= for form fields (a dict is sent as application/x-www-form-urlencoded, like curl -d) or for raw text. This converter picks json= whenever the body parses as JSON and is labelled JSON or looks like an object or array.

What is the Python equivalent of curl -k or --insecure?

Pass verify=False to the requests call, which skips TLS certificate verification just as -k does. urllib3 prints an InsecureRequestWarning each time, as a reminder it shouldn't be used in production. For a self-signed or internal certificate, point verify at its CA bundle instead, the way curl's --cacert does.

How do I send a file upload like curl -F file=@photo.jpg in Python?

Pass the fields as files=: a file field becomes open("photo.jpg", "rb"), and a text field becomes a (None, "value") tuple so it is sent as a plain form field in the same multipart body. requests builds the multipart/form-data body and its boundary for you.

Is my cURL command sent to a server when I convert it?

No. Parsing and code generation run entirely in your browser, and nothing is transmitted or stored — which matters because commands copied from DevTools routinely carry live cookies, API keys, and Authorization headers.