Convert cURL to Python requests
Convert a cURL command into Python requests code, with query parameters and headers split out cleanly instead of jammed into the URL.
Open the tool, then paste the sample input below. Everything runs locally in your browser.
The problem
A good translation uses params= for the query string and json= for JSON bodies, rather than building strings by hand. The converter produces idiomatic requests code you can drop into a script.
Sample input
curl -X GET "https://api.example.com/users?status=active" \
-H "Authorization: Bearer example_token"
Expected output
import requests
url = "https://api.example.com/users"
params = {
"status": "active"
}
headers = {
"Authorization": "Bearer example_token"
}
response = requests.get(url, params=params, headers=headers)
print(response.json())
The query string becomes a params dict and the header becomes a headers dict. For JSON bodies, use json= so requests sets the content type and serializes for you.
How to do it
- Paste the cURL command.
- Select Python requests output if available.
- Verify the query parameters and headers.
- Copy the generated Python code.
- Add a timeout and error handling for production use.
Common mistakes
- Hardcoding real tokens in the script.
- Omitting a timeout, so a hung request blocks forever.
- Putting query parameters directly in the URL when
params=is cleaner. - Using
data=for JSON whenjson=is correct. - Not checking the HTTP status code before parsing the body.
Related tools
Related guides
FAQ
How do I convert cURL to Python requests?
Paste the cURL command and select Python requests output. The converter maps method, URL, headers, query params, and body into requests code.
Should I use json or data in requests?
Use json= for JSON payloads so requests serializes the object and sets Content-Type: application/json. Use data= for form-encoded bodies.
How do I pass headers in Python requests?
Pass a dict as headers=, for example headers={"Authorization": "Bearer example_token"}.
How do I add query parameters?
Pass a dict as params=, for example params={"status": "active"}; requests builds the query string for you.
Should I add a timeout?
Yes. Always pass timeout= so a slow or hung server cannot block your program indefinitely.
The conversion runs locally in your browser; your cURL command is never uploaded.