Curl to Python: convert a curl command to requests code in seconds
Paste the command, pick Python, copy the requests code, with the parsing done in your browser.
By ClaudeGPT Si Newsroom, Editorial team
3 min read
To turn a curl command into Python, paste it into the free AyeTab cURL to Code converter, pick Python, and copy the result. You get a short script that uses the requests library, built in your browser without the command ever leaving your machine.
Why convert curl to Python at all
API docs love curl. Almost every reference page shows a request as a one-line curl command, and browser dev tools let you copy any network request in the same format. That is great for testing in a terminal, but the moment the call has to live inside a script, a scheduled job or a test suite, you want Python.
Doing the translation by hand is slow and easy to get wrong. A quoted header gets mangled, a JSON body loses an escape, or the method quietly changes. A converter does the boring part and leaves you with code you only need to read and tidy.
How to convert curl to Python with AyeTab
- Open app.ayetab.com/tools/curl-code, or press Ctrl+K (Cmd+K on a Mac) in AyeTab and type "curl".
- Paste the full curl command into the cURL box. Commands split over several lines with a trailing backslash are fine.
- Switch the output toggle from fetch to Python.
- Copy the code, or download it as a file.
There is no signup, no watermark and no upload. The page parses the command locally, so it keeps working offline once it has loaded.
A worked example
Say the docs give you this:
curl -X POST https://api.example.com/v1/items \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"name":"test"}'
The Python output follows this pattern:
import requests
response = requests.post("https://api.example.com/v1/items",
data="{\"name\":\"test\"}",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_TOKEN"
})
print(response.text)
The URL, the method from -X, each -H header and the -d body all carry over. From here you can swap the literal token for an environment variable and parse the reply with response.json().
What carries over
| curl part | Where it lands in Python |
|---|---|
URL after curl |
First argument to requests.<method>() |
-X POST |
requests.post (GET when no -X is given) |
-H "Name: value" |
Entry in the headers dict |
-d, --data, --data-raw |
The data argument |
One habit worth keeping: if a command sends a body without -X, add -X POST before you convert, so the method in the code matches what you meant.
If the converted code fails
Most problems come from the command, not the conversion. Check three things first:
- 401 or 403. The token in the copied command has probably expired. Copy a fresh request from dev tools, or load the token from an environment variable.
- 415 or a body error. The API may want JSON. Replace
data=withjson=and pass a Python dict, which also sets the Content-Type header. - A script that hangs. requests waits forever unless you pass
timeout=, so add one to every call.
Why a local converter matters
Commands copied from a browser often include cookies, session headers or bearer tokens. Pasting those into a website that processes text on its server means the secret travels to someone else's machine. AyeTab does the parsing in your browser tab, so a production token stays on your laptop.
When another tool fits better
curlconverter is an open source project that targets far more languages and handles extra curl options such as file uploads, forms and basic auth. If your command leans on those, it is the better pick. For the everyday case of headers plus a body, AyeTab is quicker, and it sits on your new tab next to the JSON formatter and the rest of the toolkit.
Get it on every new tab
The AyeTab Chrome extension replaces the new tab page with the full set of developer tools and also opens them in a side panel. Smart paste suggests the right tool for what is on your clipboard, and favorites keep the converter one click away. The web app at app.ayetab.com has the same tools if you would rather not install anything.