cURL to Python Converter
Convert curl commands to Python code using Requests or http.client. Paste a command and the Python snippet appears instantly — everything runs in your browser.
- Instant ConversionCode updates as you type
- Multiple Languages40 languages, 61 libraries
- 100% Client SideYour data stays private
How to use this tool
Steps for using the cURL to Code.
- Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
- Paste it into Enter cURL command. The Python Requests code appears instantly; other Python libraries (http.client) are in the tabs above the code.
- Set up: Install with
pip install requests. - Run it: Run the script with
python request.py. Replace placeholders such asYOUR_TOKENfirst, and check any notes under the editors for curl options that have no Requests equivalent.
Example
GET with headers → Python Requests
curl 'https://api.example.com/v1/users?page=2' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN'import requests
url = 'https://api.example.com/v1/users?page=2'
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN',
}
response = requests.get(url, headers=headers)
print(response.status_code)
print(response.text)Common use cases
- Scripts and data pipelines
- Django and Flask apps calling APIs
- Testing APIs
Converting curl to Python Requests
Requests is the most popular Python HTTP library. JSON bodies use json=, form data data= and files files=.
The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent Requests code. Options that have no Requests equivalent are listed under the editors rather than silently dropped.
Other libraries for Python, each with its own page: http.client.
Limitations
- Requests has no timeout by default — add
timeout=10in real code. - The code is a starting point: add timeouts, retries and error handling for production use.
- Secrets in the curl command are copied into the code — move them to environment variables before committing.
Frequently asked questions
Why json= instead of data=?
json= serialises the dict and sets the Content-Type to application/json, matching a JSON curl body.
How do I add a timeout?
Pass timeout=10 (seconds) to requests.post or requests.get; without it a request can wait forever.
Can I avoid installing anything?
Yes — use the standard library version: cURL to Python http.client.
Is my curl command sent to a server?
No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.