cURL to Python converter

Paste a curl command, for example one copied from your browser's network tab or from API documentation, and get the same request as Python code using the requests library. JSON bodies become Python dicts, so they are easy to edit.

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Paste the curl command. A leading curl or $ curl is fine, and so are multi-line commands ending in \.
  2. Copy the Python code and run it with the requests library installed (pip install requests).
  3. Check the note under the result for anything that was not converted.

How it works

The command is split like a shell would split it, then each option is read:

  • The method comes from -X, or is POST when there is a body or form, HEAD with -I, and GET otherwise. Standard methods use requests.get, requests.post and so on; others use requests.request.
  • Headers (-H, -A, -b, -e, and -u as Basic auth) go into a headers dict.
  • A JSON body with a JSON content type becomes json_data (true → True, null → None); other bodies become a data string; -F fields become files. With -G, data is added to the URL instead.

Worked example

curl -X POST https://api.example.com/items -H 'Content-Type: application/json' -d '{"name":"x","ok":true}'

becomes

import requests

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

json_data = {
    'name': 'x',
    'ok': True,
}

response = requests.post('https://api.example.com/items', headers=headers, json=json_data)
print(response.status_code)
print(response.text)

Tips

  • Copied browser commands contain cookies and tokens. Remove them or move them to environment variables before sharing code.
  • Use response.json() instead of response.text when the API returns JSON.
  • For JavaScript, convert the same command with cURL to fetch.

Frequently asked questions

Which curl options are converted?

-X, -H, -d and its --data variants, --data-urlencode, --json, -u, -F, -G, -I, -A, -b, -e and --url, with ', " and $'…' quotes and backslash line continuations. Options that only change curl's own behaviour, such as -L, -s or --compressed, are dropped.

When is json= used instead of data=?

When the request has a JSON content type (set with -H or added by --json) and the body is valid JSON. The body is then written as a Python dict and passed with json=. Any other body is passed as a string with data=.

What does -u user:pass become?

An Authorization header with Basic and the Base64 of user:pass, the same header curl sends. You can replace it with auth=('user', 'pass') if you prefer.

How are file uploads converted?

-F fields become a files dict. Text fields are written as (None, 'value'), files as open('name', 'rb'). Make sure the file path is right where the script runs.

What is not converted?

Proxies, timeouts, certificates, -k and output options have no direct equivalent here and are dropped or listed under the result. Add timeout= or verify= to the call yourself if you need them.

More in Developer

All tools in this category: Developer ·Updated November 4, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.