cURL to Python is a free converter that turns cURL commands into Python code using the popularrequests library. Query parameters, headers, cookies, JSON, form data, file uploads and authentication are split into clear variables. Conversion happens in your browser.
How to convert cURL to Python
- Paste the cURL command.
- Copy the Python code from the right-hand box.
- Install requests if needed (
pip install requests) and run it.
Turning a browser request into a Python script
A quick way to automate something you do on a website: open the browser’s developer tools, repeat the action, right-click the request in the Network tab and choose Copy as cURL (bash). Paste it here and you have a Python script that makes the same request. Browser requests often carry many headers you don’t need; try deleting them one at a time until the request stops working.
How the command is translated
?page=2&sort=newin the URL →params = {…}-Hheaders →headers = {…}-bor a Cookie header →cookies = {…}--jsonor a JSON-dbody →json=json_data, withtrue/false/nullturned intoTrue/False/None-d a=1&b=2→data = {…}-F [email protected]→files = {'file': open('photo.jpg', 'rb')}-u user:pass→auth=('user', 'pass'), and-k→verify=False
Tips
Add timeout=10 to the call in production code: requests waits forever by default. Useresponse.raise_for_status() to turn 4xx and 5xx responses into exceptions. To look up what a status code means, see HTTP Status Codes.
Frequently asked questions
Is it safe to paste commands with tokens or passwords?
Yes. The command is converted inside your browser and never sent anywhere. Still, remember to remove real secrets before sharing the generated code with others.
How is the command split up?
Query parameters become a params dict, cookies a cookies dict, JSON bodies a json= argument and form data a data= dict, so the code is easy to read and edit.
Why is Content-Type missing from the headers?
When you pass json= or a data dict, requests sets the correct Content-Type itself, so repeating it isn’t needed.
What does allow_redirects=False do?
curl doesn’t follow redirects unless you add -L, but requests does. The argument keeps the behaviour identical; remove it if you want redirects followed.
Last updated