How to convert a curl command to Python requests

Turn a curl command, including Copy as cURL from dev tools, into Python requests, fetch or axios code, and know which options do not carry over.

Updated 2026-12-01. Tool: cURL to Code Converter

The short answer

Map each part of the command to the matching argument: the method to requests.get or requests.post, each -H to the headers dict, -d to data= (or json= for a JSON body) and -u to auth=. curlconverter does it on the command line, and the XUtil converter does it in the browser, for fetch and axios as well.

Get the curl command

Browser dev tools write one for you: in the Network tab, right-click a request and choose Copy as cURL. Browsers offer a version for bash and one for Windows; the bash one is easier to read. The copied command includes your cookies and any authorisation header, so treat it like a password.

By hand

A typical API call:

curl https://api.example.com/users \
  -H 'Authorization: Bearer abc123' \
  -H 'Content-Type: application/json' \
  -d '{"name":"Ada"}'

In Python requests:

import requests

response = requests.post(
    'https://api.example.com/users',
    headers={'Authorization': 'Bearer abc123'},
    json={'name': 'Ada'},
)
print(response.status_code, response.json())

json= serialises the dict and sets Content-Type: application/json, so that header can go. The usual mappings:

curl requests
-X PUT requests.put(...)
-H 'Name: value' headers={'Name': 'value'}
-d 'a=1&b=2' data={'a': '1', 'b': '2'}
-d '{"a":1}' with a JSON content type json={'a': 1}
-G -d 'q=x' params={'q': 'x'}
-u user:pass auth=('user', 'pass')
-F 'file=@photo.jpg' files={'file': open('photo.jpg', 'rb')}
-b 'id=1' cookies={'id': '1'}
-k verify=False

The same request with fetch and with axios:

const response = await fetch('https://api.example.com/users', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer abc123', 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: 'Ada' }),
});

const { data } = await axios.post('https://api.example.com/users', { name: 'Ada' }, {
  headers: { Authorization: 'Bearer abc123' },
});

With curlconverter

curlconverter is an open-source converter with a command-line version. Install it with npm and replace curl with curlconverter. Python requests is the default output; --language picks another, such as javascript or node-axios:

npm install --global curlconverter
curlconverter https://api.example.com/users -H 'Authorization: Bearer abc123'
curlconverter --language node-axios https://api.example.com/users

To convert a whole copied command, word curl included, pipe it in and pass -, for example pbpaste | curlconverter - on macOS. API clients such as Postman and Insomnia can also import a curl command and generate code from it.

What to watch for

  • Content type: -d sends application/x-www-form-urlencoded unless you set another type. requests sets that type when data= is a dict but sends no content type when it is a string, so a string body copied from curl may need the header added.
  • Exact bytes: json= re-serialises the body, with spaces after colons and commas. If the server checks a signature over the raw body, send the original string with data= and set the header yourself.
  • Redirects: curl follows redirects only with -L. requests follows them for every method except HEAD, and fetch and axios follow them too.
  • Shell syntax: $TOKEN, $(...) and @file are expanded by the shell or by curl, not by a converter. Replace them with real values in the code.
  • Timeouts: requests waits indefinitely unless you pass timeout=, so add one in production code.
  • -k: verify=False turns off certificate checks. Do not leave it in production code; point verify= at a CA bundle file for a private certificate authority instead.

Do it in your browser

The cURL to Code Converter turns a pasted curl command, written for bash or Windows cmd, into fetch, axios or Python requests code as you type. It handles shell quoting, joined flags such as -sSL, --json, -u, -F and -G, turns a JSON body into an object literal when that gives back the same JSON, and lists every option it did not carry over, such as proxies and timeouts. It does not expand shell variables or read @ files. The command, and whatever tokens it holds, stays in your browser.

Frequently asked questions

How do I convert curl to Python requests?
Pass the URL to requests.get or requests.post, put each -H header in a headers dict, and pass -d as data= or a JSON body as json=. A converter such as curlconverter or the XUtil cURL converter does the mapping for you.
How do I copy a request as curl from Chrome?
Open dev tools, go to the Network tab, right-click the request and choose Copy, then Copy as cURL. The command includes cookies and authorisation headers, so do not paste it anywhere you would not paste a password.
What is the requests equivalent of curl -k?
verify=False. It turns off certificate verification, so use it only against a test server, and pass the path of a CA bundle to verify= when the server uses a private certificate authority.
Why does my converted request behave differently from curl?
Common causes are a missing Content-Type header for a string body, a redirect that requests followed and curl did not, and shell variables or @file references that were never replaced with real values.