
Options
Paste a curl command and get the same request as Python requests code, updated as you type. Headers, cookies, query strings, JSON and form bodies, file uploads, basic and digest auth, proxies, and timeouts are all translated, and anything that works differently in Python is pointed out under the code. It reads commands copied from Chrome, Firefox, and Edge DevTools in both the bash and Windows cmd formats, along with API docs and Postman. Everything runs in your browser.
How to convert curl to Python
- Copy a request as curl. In Chrome or Edge DevTools, open the Network tab, right-click a request, and choose Copy, then Copy as cURL. Firefox and Postman have the same option.
- Paste it into the left pane. The Python code appears on the right.
- Read the notes under the code for anything that needs your attention, like a file path or a shell variable.
- Click Copy or Download .py, then run it with
pip install requestsdone first.
How curl options map to requests
| curl | Python requests |
|---|---|
-X POST | requests.post(), or requests.request('PURGE', ...) for other methods |
-H 'Name: value' | headers={'Name': 'value'} |
-b 'a=1; b=2' or a Cookie header | cookies={'a': '1', 'b': '2'} |
-d, --data-raw, --data-urlencode | data={...} for form fields, or data='...' for other text |
--json, or -d with a JSON content type | json={...} |
-F 'file=@photo.jpg' | files={'file': open('photo.jpg', 'rb')} |
-u user:pass | auth=('user', 'pass'), or HTTPDigestAuth with --digest |
-G with -d | params={...} |
-k or --insecure | verify=False |
-x http://proxy:8080 | proxies={'http': ..., 'https': ...} |
-m 30, --connect-timeout 5 | timeout=30, or timeout=(5, 30) |
-o file | The response is written to that file with response.content |
-f or --fail | response.raise_for_status() |
Flags that only change what curl prints, like -s, -v, and -i, have no effect on the request and are skipped.
Differences between curl and requests
- Redirects: curl doesn't follow redirects unless you pass
-L, but requests follows them by default. Turn on Match curl's redirect behavior to addallow_redirects=Falsewhen-Lis missing. - Timeouts: requests waits forever by default. Add a timeout for anything that runs unattended.
- Compression: requests handles gzip on its own, so
--compressedisn't needed. Brotli responses need thebrotlipackage installed. - Content-Length: requests works this out from the body, so the header is left out.
- Browser headers: commands copied from a browser include headers like
sec-ch-uaandsec-fetch-modethat servers rarely need. Turn on Drop browser-only headers for shorter code.
Frequently asked questions
Does it work with "Copy as cURL" from Chrome?
Yes, in both formats. The bash format and the Windows cmd format, with its ^ escapes, are both read correctly, including bodies quoted with $'...'.
Can it convert several curl commands at once?
Yes. Paste them one after another, such as from Copy all as cURL, and each one becomes its own request in the same script. Turn on Use requests.Session() to share cookies and connections between them.
Why does my JSON body use json= instead of data=?
When the body is valid JSON and the content type is JSON, json= is the cleanest way to send it: requests sets the Content-Type header for you. Turn off Use json= for JSON bodies to keep the body as an exact string instead.
What happens to file uploads?
Each -F field that points to a file becomes an entry in files= that opens the file, with the filename and content type if you gave them. Plain -F fields are sent in the same multipart form, just like curl does.
What about $TOKEN and other shell variables?
By default they're read from your environment with os.environ, the same way the shell would fill them in, so tokens stay out of your code. Turn off Read shell variables from the environment to keep them as plain text.
Is my command sent anywhere?
No. The conversion happens in your browser. Nothing is sent to a server, so tokens and cookies in your command stay on your device.
