Skip to main content
Back to tools

cURL to Python

Convert a curl command to Python requests

About cURL to Python

Generates Python code for the requests library from a cURL command, calling requests.get, requests.post or another method helper with the headers in a dict. A JSON -d payload becomes json= with True, False and None converted, -u becomes auth=('user', 'pass'), and form fields become a data= dict. The command is parsed in your browser and never uploaded.

Category: API.

Frequently asked questions

Which Python library does the generated code use?

▾

It uses requests, a third-party package you install with pip install requests. The calls are synchronous: requests.get, requests.post and the other method helpers, or requests.request('PURGE', ...) for non-standard methods, and the script ends with print(response.json()).

How is a JSON -d payload converted to Python?

▾

When the payload is valid JSON, it is rewritten as a Python dict and passed as json=, with true, false and null turned into True, False and None. The Content-Type header is left out because requests sets application/json itself when json= is used.

Are -F fields sent as multipart/form-data by requests?

▾

No. -F fields, like -d data sent with Content-Type: application/x-www-form-urlencoded, become a data= dict that requests encodes as a regular URL-encoded form. For multipart or file uploads, move them to files=; a value like @photo.jpg is copied as plain text.

How are -u, -k, -b and --max-time handled in the Python code?

▾

-u user:pass becomes auth=('user', 'pass'), and a matching Basic Authorization header is also written, which you can delete. -k, -b and --max-time are not translated, so add verify=False, cookies= or timeout= by hand; redirects need no flag because requests follows them by default.

Related tools