How to convert cURL to Python requests
Use the converter above: paste your cURL command, choose Python (Requests), and click convert. The tool maps cURL options to Python requests calls so you get runnable code with the same URL, method, headers, and body.
If you have many cURL commands or need other languages (JavaScript, Go, Java, PHP), use our full cURL to Code Converter. For step-by-step guides and examples, see cURL to Python Requests: Complete Guide.
cURL vs Python requests — syntax comparison
cURL uses flags and positional args; Python requests uses method calls and keyword arguments. The converter handles the mapping so you don't have to.
| cURL | Python requests |
|---|---|
-X POST | requests.post(url, ...) |
-H "Content-Type: application/json" | headers={'Content-Type': 'application/json'} |
-d '{"key":"val"}' | json={'key': 'val'} |
-u user:pass | auth=('user', 'pass') |
-H "Authorization: Bearer TOKEN" | headers={'Authorization': 'Bearer TOKEN'} |
Common cURL flags and their Python equivalent
-X METHOD→requests.get/post/put/delete/patch(url, ...)-H "Name: value"→headers={'Name': 'value'}-d '...'→data=...orjson=...for JSON-u user:pass→auth=('user', 'pass')--connect-timeout N→timeout=N
Code examples: GET, POST, headers, auth
After converting, you get Python like this. For GET with headers:
import requests
url = "https://api.example.com/data"
headers = {"Authorization": "Bearer YOUR_TOKEN"}
r = requests.get(url, headers=headers)
print(r.json())For POST with JSON body:
import requests
url = "https://api.example.com/users"
headers = {"Content-Type": "application/json"}
payload = {"name": "John", "email": "john@example.com"}
r = requests.post(url, json=payload, headers=headers)
print(r.status_code)The converter above fills in url, headers, and body from your cURL so you can run or tweak the code immediately. For more examples and edge cases, use our cURL to Python Requests tool page or the full cURL Converter.
Why convert cURL to Python?
cURL is ideal for one-off tests in the terminal. Python with requests is better for scripts, automation, and production code: you get loops, error handling, and integration with the rest of your app. Converting cURL to Python lets you keep the exact request (URL, headers, body) while moving from the command line into code.
This converter is free, runs in your browser, and doesn't store your commands. For HAR-based conversion (browser network export to cURL then to code), use our HAR to cURL tool first, then paste the generated cURL here.