🔁 cURL to Python Converter — Generate requests Code
Convert any cURL command to Python requests code instantly. Supports headers, POST body, auth, JSON. Free online curl to Python converter.
Paste your curl command and select the Python tab to get production-ready Python requests code. Handles all curl flags: -H headers, -d POST data, -u basic auth, -X methods, and JSON bodies. Copy and paste straight into your project.
How to Use
Paste your cURL command
Paste your full curl command (starting with "curl") into the input area. Multi-line commands with \ are supported.
Choose a language
Click a language tab: Python, JavaScript, PHP, or Go. The code updates instantly.
Copy the code
Click Copy to copy the generated code. It handles headers, auth, and JSON bodies.
Frequently Asked Questions
Complete Guide: cURL to Code Converter
The cURL to Code tool transforms raw curl terminal commands into clean, ready-to-run code snippets for JavaScript fetch, Axios, Python Requests, PHP cURL, and more. Whether you copied a command from browser DevTools or an API's documentation, this converter eliminates the tedious manual translation work.
Anatomy of a cURL Command
Before conversion, it helps to understand what each flag means:
- -X POST — Sets the HTTP method. Without it, GET is assumed.
- -H "Content-Type: application/json" — Adds a request header. You can repeat -H for multiple headers.
- -d '{"key":"value"}' — Sends a request body. Implies POST if no -X is given.
- --data-raw — Like -d but does not interpret
@as a file reference. Common in DevTools exports. - -u user:password — Basic Authentication shorthand. The converter encodes this as a
Authorization: Basicheader. - -k or --insecure — Skips TLS certificate verification. Never use this in production code.
- -b "session=abc" — Sends cookies. Equivalent to adding a
Cookieheader. - -F "file=@photo.jpg" — Sends a multipart/form-data body, typically for file uploads.
Converting to JavaScript Fetch API
The native fetch() API maps cleanly to cURL flags. A POST with JSON body becomes:
fetch('https://api.example.com/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer TOKEN'
},
body: JSON.stringify({ name: 'Alice' })
})
.then(res => res.json())
.then(data => console.log(data));
One pitfall: fetch does not follow redirects that change the method from POST to GET by default. If the API redirects, check the redirect option.
Converting to Axios
Axios automatically serialises JavaScript objects to JSON when you set Content-Type: application/json, so you can pass the object directly to data instead of calling JSON.stringify. The converter handles this distinction for you.
Converting to Python Requests
Python's requests library is arguably the most readable target:
import requests
response = requests.post(
'https://api.example.com/users',
headers={'Authorization': 'Bearer TOKEN'},
json={'name': 'Alice'}
)
print(response.json())
Note that using the json= keyword argument automatically sets the Content-Type header and encodes the body, so you do not need to specify it manually.
Common Pitfalls with Special Characters
Headers copied from terminals often contain invisible Unicode dashes or smart quotes instead of plain ASCII hyphens and straight quotes. This causes signature mismatches in APIs like AWS that sign headers. Always inspect pasted commands for these substitutions before converting.
When -d contains shell variables like $TOKEN, the converter cannot resolve them. Replace them with literal values or environment variable references in your target language before running the converted code.
The -k / --insecure Flag Warning
Many teams paste cURL commands that include -k because someone bypassed a certificate error during testing. The converter will include the equivalent insecure option in the output, but it also raises a visible warning. In Python that means verify=False; in Node.js it requires setting NODE_TLS_REJECT_UNAUTHORIZED=0. Both are dangerous in production and will expose your application to man-in-the-middle attacks.
Handling Cookies
When a cURL command uses -b to send cookies, the converter places the value directly in a Cookie header. For browser-based fetch calls, be aware that credentials: 'include' controls whether the browser sends its own cookies automatically, which is separate from manually constructed cookie strings.
Multipart Form Uploads
File upload commands using -F are translated to FormData in JavaScript or files= in Python Requests. Because the file path in the original cURL command is local to the machine where it was run, the converter replaces the file reference with a placeholder you must substitute with your actual file input.
Related Tools
After converting a command, you may want to inspect the live headers returned by the endpoint — use the HTTP Headers Checker for that. If any header values are Base64-encoded, the Base64 Encoder can decode them instantly.