curl to Python Converter

Convert a curl command to Python requests code instantly in your browser. The command stays on your device.

Your curl command is converted to Python locally in your browser and never uploaded, but avoid pasting real production tokens or credentials into any tool.

Want to send the request? Try the API Request Client.

About cURL to Python

This curl to python converter takes a curl command you copied from a terminal, browser DevTools, or API docs and rewrites it as a clean Python script built on the requests library. As a curl to requests converter it reads flags like -X, -H, -d, --data-raw, --json, -u, -b, and -G, picks the right HTTP method, and chooses json= for valid JSON bodies or data= for form payloads so the call works the first time you run it. It is handy when you are moving a quick API test into a Python script, a notebook, or a backend integration without retyping headers by hand. The whole conversion runs in your browser, so the curl command and any tokens inside it are processed locally on your device and are never uploaded.

Features

How to use the cURL to Python

  1. Paste your curl command into the cURL command box.
  2. Read the generated Python requests script in the output panel.
  3. Check the warning banner for any flags that were adjusted or skipped.
  4. Click Copy, or download the script as request.py.

Example

Input

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

Output

import requests

url = "https://api.example.com/users"
headers = {
    "Content-Type": "application/json",
}
payload = {
    "name": "Ada"
}

response = requests.request("POST", url, headers=headers, json=payload)
print(response.status_code)
print(response.text)

A JSON body is passed with json= so requests serializes it for you.

Common errors & troubleshooting

Frequently asked questions

How do I convert a curl command to Python?
Paste the curl command into the input box and the converter renders a Python requests script on the right that you can copy or download as request.py.
Does this generate code for the requests library or urllib?
It targets the popular requests library and emits a requests.request(method, url, ...) call. Install it with pip install requests before running the script.
When does the converter use json= versus data=?
It uses json= when the body is valid JSON (sent with --json or a JSON Content-Type) so requests serializes the dict, and data= for form-encoded or raw string bodies.
How is a curl -u basic auth value handled in the Python output?
A -u or --user value is base64-encoded into an Authorization: Basic header in the headers dict, matching what curl sends on the wire.
Is my curl command uploaded when I convert it to Python?
No. The curl to python conversion runs entirely in your browser, so the command and any credentials in it stay on your device.

Related tools

All ArrayKit tools