Skip to content

HTTP & API tools / FREE ONLINE TOOL

cURL to Python Requests

Converts cURL commands into Python code using the requests library.

Your command stays on this device

This tool runs entirely inside your web browser. Your command is processed on your own device and is never sent to our servers. How this works

Python requests

cURL to Python is a free converter that turns cURL commands into Python code using the popularrequests library. Query parameters, headers, cookies, JSON, form data, file uploads and authentication are split into clear variables. Conversion happens in your browser.

How to convert cURL to Python

  1. Paste the cURL command.
  2. Copy the Python code from the right-hand box.
  3. Install requests if needed (pip install requests) and run it.

Turning a browser request into a Python script

A quick way to automate something you do on a website: open the browser’s developer tools, repeat the action, right-click the request in the Network tab and choose Copy as cURL (bash). Paste it here and you have a Python script that makes the same request. Browser requests often carry many headers you don’t need; try deleting them one at a time until the request stops working.

How the command is translated

  • ?page=2&sort=new in the URL → params = {…}
  • -H headers → headers = {…}
  • -b or a Cookie header → cookies = {…}
  • --json or a JSON -d body → json=json_data, with true/false/null turned into True/False/None
  • -d a=1&b=2 → data = {…}
  • -F [email protected] → files = {'file': open('photo.jpg', 'rb')}
  • -u user:pass → auth=('user', 'pass'), and -k → verify=False

Tips

Add timeout=10 to the call in production code: requests waits forever by default. Useresponse.raise_for_status() to turn 4xx and 5xx responses into exceptions. To look up what a status code means, see HTTP Status Codes.

Worked example: creating a user with JSON

Paste this command:

curl -X POST 'https://api.example.com/v1/users' \
  -H 'Authorization: Bearer abc123' \
  --json '{"name":"Ada","admin":false,"tags":["dev","ops"]}'

You get back:

import requests

headers = {
    'Authorization': 'Bearer abc123',
    'Accept': 'application/json',
}

json_data = {
    'name': 'Ada',
    'admin': False,
    'tags': [
        'dev',
        'ops',
    ],
}

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

print(response.json())

Note three conversions: --json grows an Accept header, the JSON body becomes ajson= argument, and true/false become Python’sTrue/False.

Worked example: uploading a file

Paste this command:

curl -X POST 'https://files.example.com/upload' -F 'title=Report' -F '[email protected]'

You get back:

import requests

data = {
    'title': 'Report',
}

files = {
    'file': open('report.pdf', 'rb'),
}

response = requests.post('https://files.example.com/upload',
    data=data,
    files=files,
    allow_redirects=False,
)

print(response.text)

Plain fields become data, file fields become files opened in binary mode. The path is read where the script runs, so adjust 'report.pdf' to the real location.

Troubleshooting pasted commands

  • Single quotes fail on Windows. --json '{"a":1}' works in bash but not in cmd.exe. Use double quotes with backslash escapes, switch to PowerShell, or put the body in a file and pass--data @body.json instead.
  • Copied browser commands are bloated. Dev-tools copies include a dozen headers the API never checks. As described above under “Turning a browser request into a Python script”, delete headers until it breaks.
  • -k becomes verify=False. Fine against a local test server, but fix the certificate before any real traffic goes over it.
  • Secrets travel with the code. Bearer tokens and passwords paste straight through into the output — redact them before the script leaves your machine.

Frequently asked questions

Is it safe to paste commands with tokens or passwords?

Yes. The command is converted inside your browser and never sent anywhere. Still, remember to remove real secrets before sharing the generated code with others.

How is the command split up?

Query parameters become a params dict, cookies a cookies dict, JSON bodies a json= argument and form data a data= dict, so the code is easy to read and edit.

Why is Content-Type missing from the headers?

When you pass json= or a data dict, requests sets the correct Content-Type itself, so repeating it isn’t needed.

What does allow_redirects=False do?

curl doesn’t follow redirects unless you add -L, but requests does. The argument keeps the behaviour identical; remove it if you want redirects followed.

Last updated

KEEP GOING

Missing a feature, or need a tool we don’t have? Suggest it.