Convert curl commands to Python requests code instantly. Free online curl to Python converter that handles headers, authentication, and JSON bodies.
You have a curl command that works. Maybe you copied it from Chrome DevTools after inspecting a network request, or you pulled it from Stripe's API docs. Now you need that same request in Python so you can automate it, add it to a script, or build it into a pipeline.
Translating curl to Python by hand is tedious when the command includes five headers, a JSON body, and basic authentication. You have to map each flag to its requests equivalent, get the quoting right, and remember whether auth uses a tuple or a header.
This converter does the translation in one click. Paste a curl command, get working Python code that uses the requests library, and move on.
Every curl flag has a direct equivalent in Python's requests library. Here is how this converter maps them:
| Curl flag | Python requests equivalent |
|---|---|
| -X POST | requests.post() |
| -H 'Key: Value' | headers={'Key': 'Value'} |
| -d '{"key":"val"}' | data='{"key":"val"}' |
| -u user:pass | auth=('user', 'pass') |
| -k | verify=False |
| -L | allow_redirects=True (default) |
| -b 'cookie=val' | Added to headers as Cookie |
The converter uses the requests library because it is the de facto standard for HTTP in Python. It is installed in virtually every Python environment and its API maps cleanly to curl's options.
When a curl command includes -d '{"key": "value"}' along with a Content-Type: application/json header, the converter generates code that passes the JSON string to the data parameter. If you prefer, you can replace data= with json= and pass a Python dictionary instead. The requests library will serialize it and set the Content-Type header automatically.
The converter keeps the output close to the original curl command so the request is identical. Switching from data to json is a one-line edit you can make after pasting the generated code.
Curl supports basic auth with -u user:password. The converter maps this to the auth parameter, which takes a tuple: auth=('user', 'password'). This is cleaner than manually base64-encoding the credentials and setting the Authorization header yourself.
For bearer tokens, curl uses -H 'Authorization: Bearer token123'. The converter passes this through as a regular header in the headers dictionary. The same applies to API keys sent via custom headers.
If your curl command uses OAuth tokens, session cookies, or other authentication methods, the converter preserves them exactly as they appear in the original command.
The output is a complete, runnable Python script. It includes the import requests statement, defines headers and body as variables, makes the request, and prints the status code and response text. You can paste it into a .py file, a Jupyter notebook, or a Python REPL.
For production use, you will likely want to add error handling (try/except), use response.json() instead of response.text for JSON APIs, and move credentials out of the code and into environment variables.
If you are working with async Python, the generated code is a starting point. You can adapt the requests call to use aiohttp or httpx with the same headers and body structure.
The fastest way is Chrome DevTools: open the Network tab, find the request, right-click, and select "Copy as cURL." This captures every header the browser sent, including cookies and authorization tokens. Paste it directly into this converter.
API documentation is another common source. Services like Stripe, GitHub, Twilio, and OpenAI provide curl examples for every endpoint. Converting these to Python saves you from manually mapping each flag.
Paste your curl command into the input field above, make sure "Python" is selected as the target language, and click Convert. The output uses the requests library and is ready to paste into any Python file.
Yes. Each -H flag in the curl command becomes a key-value pair in the Python headers dictionary. The converter handles any number of headers.
The generated code works with Python 3. The requests library supports Python 3.7+ and the generated syntax is compatible with all modern Python versions.
No. All conversion happens in your browser. Nothing is transmitted to any server. You can safely paste commands containing API keys or internal URLs.
The converter treats --data-raw and --data-binary the same as -d. All three map to the data parameter in the Python output.
The generated code uses requests because it is the most widely used Python HTTP library. The headers dictionary and body string work with any HTTP client. You can adapt the output to aiohttp or httpx by changing the function call.
Structured page data instead of raw HTML. Your agent processes less, decides faster, and costs less to run.