Convert a curl command to Python requests code instantly in your browser. The command stays on your device.
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.
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
Generates a requests.request(method, url, ...) call with the inferred HTTP method
Builds a Python headers dict from every -H/--header flag
Uses json= for valid JSON bodies and data= for form-encoded payloads
Pretty-prints JSON bodies as a Python dict literal you can edit
Maps -u/--user to a Basic auth Authorization header and handles cookies, user-agent, and referer
Appends -G/--get data to the URL as a query string
Warns about flags with no requests equivalent, like -k and output-to-file options
Copy the result or download it as request.py with one click
How to use the cURL to Python
Paste your curl command into the cURL command box.
Read the generated Python requests script in the output panel.
Check the warning banner for any flags that were adjusted or skipped.
A JSON body is passed with json= so requests serializes it for you.
Common errors & troubleshooting
The output uses data= when you expected json=. — Send the body with --json or add -H "Content-Type: application/json" so the converter recognizes it as JSON and switches to json=.
Running the script raises ModuleNotFoundError: No module named 'requests'. — Install the dependency first with pip install requests; the generated code targets the third-party requests library, not urllib.
A JSON body comes out as a quoted string instead of a Python dict. — That happens when the body is not valid JSON. Fix the JSON, or keep it as a string and send it with data=.
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
cURL to Go — Convert a curl command to Go net/http code.
cURL to PHP — Convert a curl command to PHP cURL code.