cURL to Python Converter
Runs entirely in your browser
Paste a curl command and get equivalent Python requests code, generated directly in your browser.
What is cURL to Python?
cURL to Python parses a curl command's method, URL, headers and body, and generates equivalent Python code using the requests library — useful when porting a curl example from API documentation into a Python script.
How to use cURL to Python
- Paste a curl command into the Input box.
- Click Convert.
- Copy the generated Python code.
Features
- Uses the requests library — Python's de facto HTTP standard.
- Supports method, headers, body and HTTP Basic auth.
- Never runs the request itself.
- 100% client-side — your command never leaves your browser.
Example
This curl command:
curl -X POST 'https://api.example.com/users' \
-H 'Content-Type: application/json' \
-d '{"name":"Ada"}'
becomes:
import requests
response = requests.post(
'https://api.example.com/users',
headers={
'Content-Type': 'application/json'
},
data='{"name":"Ada"}'
)
print(response.status_code)
print(response.text)
Tips for Python developers
- Install the library first with
pip install requests— it isn't part of the Python standard library. - If the body is JSON, prefer passing a dict to
json=instead of a string todata=— requests will serialize it and set the Content-Type header for you. requests.post(...)does not raise an exception for a 4xx or 5xx response — callresponse.raise_for_status()if you want failed requests to throw.- Use
response.json()instead ofresponse.textwhen the response body is JSON, and passtimeout=10to avoid a request hanging indefinitely.
Is cURL to Python Converter safe?
Yes. Parsing your curl command and generating the Python requests code both happen locally in your browser — the command you paste, including any headers or tokens it contains, is never uploaded to our servers, and nothing is installed or executed until you run the generated script yourself.
Frequently Asked Questions
Which Python library is used?
The requests library — the de facto standard for HTTP in Python. It needs to be installed separately with pip install requests.
Which curl flags are supported?
-X/--request, -H/--header, -d/--data (and --data-raw/--data-binary/--data-urlencode), -u/--user, -A/--user-agent, -b/--cookie, --url, and a bare URL. Other flags are ignored rather than causing an error.
Does this run the request?
No. It only generates the Python code — you run it yourself.