cURL to Python Converter
Paste a curl command and get Python requests code, with every assumption written down. If the command uses something this tool cannot convert exactly, you get the reason and no code. It parses text only: it never runs the command, reads files or sends requests.
Read as text in this page. It is never run, saved or sent anywhere.
Python code generated
Python requests code
# Assumption: Converted as text only. Nothing was executed, no files were read and no request was sent.
# Assumption: allow_redirects=False matches curl, which does not follow redirects without -L.
# Assumption: Python requests sends its own User-Agent, Accept and Accept-Encoding defaults, reads proxy settings and ~/.netrc from the environment, and may normalise the URL's encoding.
import requests
url = "https://api.example.com/v1/users"
headers = {
"Accept": "application/json",
}
response = requests.request("GET", url, headers=headers, allow_redirects=False)
print(response.status_code)
print(response.text)
Conversion assumptions
- Converted as text only. Nothing was executed, no files were read and no request was sent.
- allow_redirects=False matches curl, which does not follow redirects without -L.
- Python requests sends its own User-Agent, Accept and Accept-Encoding defaults, reads proxy settings and ~/.netrc from the environment, and may normalise the URL's encoding.
- Python requests takes headers as a dict, so it cannot send a header name twice. Repeated headers are combined into one, or rejected when combining them would be unsafe.
Supported curl syntax
The converter handles an explicit method, headers and a literal body, using these flags:
-X--request-H--header-d--data--data-ascii--data-binary--data-raw
The command needs exactly one http:// or https:// URL. Single quotes, double quotes, backslash escapes and backslash line continuations are read the way a POSIX shell reads them, so a multiline command copied from API docs works.
Examples
GET with a header
curl https://api.example.com/v1/users \
-H 'Accept: application/json'# Assumption: Converted as text only. Nothing was executed, no files were read and no request was sent.
# Assumption: allow_redirects=False matches curl, which does not follow redirects without -L.
# Assumption: Python requests sends its own User-Agent, Accept and Accept-Encoding defaults, reads proxy settings and ~/.netrc from the environment, and may normalise the URL's encoding.
import requests
url = "https://api.example.com/v1/users"
headers = {
"Accept": "application/json",
}
response = requests.request("GET", url, headers=headers, allow_redirects=False)
print(response.status_code)
print(response.text)
POST with a JSON body
curl -X POST https://api.example.com/v1/users \
-H 'Content-Type: application/json' \
-d '{"name": "Ada", "role": "admin"}'# Assumption: Converted as text only. Nothing was executed, no files were read and no request was sent.
# Assumption: allow_redirects=False matches curl, which does not follow redirects without -L.
# Assumption: Python requests sends its own User-Agent, Accept and Accept-Encoding defaults, reads proxy settings and ~/.netrc from the environment, and may normalise the URL's encoding.
# Assumption: The body is sent byte for byte as a string. It is not parsed as JSON or form fields.
import requests
url = "https://api.example.com/v1/users"
headers = {
"Content-Type": "application/json",
}
data = "{\"name\": \"Ada\", \"role\": \"admin\"}"
response = requests.request("POST", url, headers=headers, data=data, allow_redirects=False)
print(response.status_code)
print(response.text)
What it refuses
Every other flag is rejected, including the common -L, -s and --compressed, because dropping one silently would give you code that behaves differently from your command. Shell features are rejected too, since their result is only known when a shell runs them. These are the messages you would see:
curl -L -s --compressed https://example.com- -L is not supported, so no code was generated. Remove it and account for its effect yourself.
- -s is not supported, so no code was generated. Remove it and account for its effect yourself.
- --compressed is not supported, so no code was generated. Remove it and account for its effect yourself.
curl https://example.com/$(whoami)- Command substitution with $(...) is not supported. It was not run.
curl https://example.com; rm -rf build- The shell operator ; is not supported. Convert a single curl command with no pipes, redirects or chaining.
curl -d @payload.json https://example.com- -d with @ reads a local file, which is not supported and was not read. Use --data-raw if the @ is literal.
What this tool never does
The command is parsed as plain text in your browser. Nothing is executed, $(...) and variables are not expanded, referenced files are not read and the target URL is not contacted. What you paste is not added to the page URL, browser storage, logs or analytics, and reloading the page clears it.
Frequently asked questions
How do I convert a curl command to Python requests?
Paste the command into the box. If every part of it is supported, you get a requests.request call to copy, with its assumptions listed beside it. If not, you get no code and a reason for each part that blocked the conversion.
Does this tool run my curl command?
No. It reads the command as text. It never runs the command, expands substitutions, reads files or sends the request.
Is it safe to paste a command with an API token?
What you paste stays in this page and is not put in the URL, browser storage, logs or analytics. The generated code contains the same token in plain text, so treat it like any other secret before you commit or share it.
Why are -L, -s and --compressed rejected?
The converter refuses any flag outside its supported list rather than dropping it silently. To get past them, delete the flag. -s only silences curl, so nothing is lost. For -L, change the generated code to allow_redirects=True. For --compressed, requests already asks for gzip and decodes the response.
What happens to duplicate headers?
Python requests takes headers as a dict, so it cannot send a header name twice. Repeated headers are combined with a comma, or a semicolon for Cookie, and an assumption names the header. Repeats of Authorization, Content-Type, Content-Length, Host and User-Agent are rejected, because a combined value would likely be misread.
Why does the code set allow_redirects=False?
curl does not follow redirects unless you pass -L, but requests does by default. Setting allow_redirects=False keeps the Python call matching the command you pasted.
Can it convert file uploads?
No. -d @file and -H @file are rejected and the file is not read. Other upload flags such as -F and -T are rejected as unsupported.