cURL to Python requests converter

Good for turning API examples or requests copied from the browser into Python scripts and automation.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter curl command.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

The command is split the way bash does it and -X, -H, -d, --data-raw, --data-urlencode, --json, -F, -u, -b, -G, -I and -k are read. The body is sent as written through data=, -F becomes files= with (None, value) entries, -u becomes auth= and -k becomes verify=False. A body with non-ASCII text is encoded as UTF-8, as curl sends it.

Example

Result: Python code: import requests headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer TOKEN', } data = '{"product":"oud","qty":2}' response = requests.post('https://api.example.com/v1/orders', headers=headers, data=data); Method: POST; Notes: No notes.

curl -X POST 'https://api.example.com/v1/orders' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer TOKEN' \
  -d '{"product":"oud","qty":2}'
import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer TOKEN',
}

data = '{"product":"oud","qty":2}'

response = requests.post('https://api.example.com/v1/orders', headers=headers, data=data)

Limits and caveats

  • Reading @file, $VAR variables and Windows cmd syntax are not supported.
  • requests follows redirects for GET and POST by default, while curl needs -L.

Questions about this tool

Why is the body sent with data= instead of json=?

So the bytes match what you wrote in curl exactly and the Content-Type header stays as in the original command.

Why was .encode('utf-8') added?

requests encodes a text body as latin-1 and fails on Arabic, while curl sends UTF-8.

Do I need to install anything?

Only the requests library, installed with pip install requests.