cURL to Python Requests Converter
Paste any cURL command and get the equivalent Python requests code.
Ready.
About cURL to Python Requests Converter
The Python requests library is the most popular HTTP library for Python — downloaded over 300 million times per month. When you have a working cURL command from API documentation and need to integrate it into Python code, this converter saves you from manually translating cURL flags to requests parameters.
cURL to Python Mapping Reference
-X GET → requests.get(url) | -X POST → requests.post(url) | -H 'Header: value' → headers={'Header': 'value'} | -d 'data' → data='data' | -d '{"json":true}' (with Content-Type JSON) → json={"json": True} | --form key=val → files={'key': val} | -k → verify=False | -u user:pass → auth=('user','pass')
Sending JSON vs Form Data
When your cURL uses -H 'Content-Type: application/json' with a JSON body, use the json= parameter in requests — it automatically sets the Content-Type header and serializes Python dicts to JSON. When your cURL uses --form or -F, use the data= or files= parameter.
Session Reuse for Performance
For making multiple API calls to the same host, use requests.Session() to reuse TCP connections and share headers across requests: with requests.Session() as s: s.headers.update(headers); r = s.get(url).
Error Handling Best Practice
Always call response.raise_for_status() after a request to automatically raise a requests.HTTPError for 4xx and 5xx responses. Wrap in a try/except to handle gracefully and log the error status code.