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.
Practical example and expected result
Convert a cURL command into Python requests code, with query parameters and headers split out cleanly instead of jammed into the URL. In practice, this is most useful when you need a quick, repeatable check on a cURL command before adding it to a ticket, pull request, test fixture, or support note.
A realistic input for this workflow is curl -X GET "https://api.example.com/users?status=active" \ -H "Authorization: Bearer example_token". The expected result should resemble import requests url = "https://api.example.com/users" params = { "status": "active" } headers = { "Authorization": "Bearer example_token" } ..., with the same important values preserved.
Troubleshooting checklist
- Confirm you copied the complete cURL command and not only a partial line or truncated preview.
- Run the local tool once with a safe sample, then repeat with the real data only if your team policy allows it.
- Check quoting, escaping, whitespace, encoding, timestamps, and environment-specific values before trusting the result.
- Before sharing output, remove secrets, tokens, cookies, customer data, and production hostnames that are not needed for the review.
Next useful steps
- Open this example in cURL Converter → for a related validation or follow-up step.
- Generate request snippets for a related validation or follow-up step.
- Parse and build HTTP headers for a related validation or follow-up step.
- Use Magic Box when you are not sure which tool should handle the next artifact.
Review checklist before sharing the result
For Convert cURL to Python requests, the safest workflow is to test with a small sample, confirm the output shape, then repeat with the real artifact only when needed. Keep the original input open until you verify that no value was dropped, decoded twice, sorted unexpectedly, or changed from text into a different type.
Before copying the result into a pull request, issue, chat thread, or support ticket, scan for private values. Replace real IDs, bearer tokens, session cookies, email addresses, internal hostnames, and customer data with placeholders. If another tool is listed above, use it as the second pass rather than manually editing complex output.
- Keep one line of context explaining why the transformation was needed.
- Preserve enough sample structure for a reviewer to reproduce the result locally.
- Note any assumptions about encoding, timezone, delimiter, schema version, or runtime environment.