Free tool

curl to Python

Paste a curl command and get the same request in Python, written with the requests library. No account; the command is only read, never run.

An example: a POST with JSON and a token

curl -X POST 'https://api.example.com/items?page=1' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -d '{"name":"pen","price":2.5}'

becomes, in Python:

Python

import requests

headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_TOKEN",
}
data = "{\"name\":\"pen\",\"price\":2.5}"

response = requests.post("https://api.example.com/items?page=1", headers=headers, data=data)
print(response.status_code)
print(response.text)

About the Python code

The code uses requests, the usual HTTP library for Python: install it with pip install requests.

Headers (-H) become a headers dictionary, the body (-d, --data-raw, --json) is sent as data, and -u user:password becomes an Authorization header. For a JSON body you can also pass a dictionary as json= and leave out the Content-Type header.

response.status_code is the site's status and response.text the page. Add timeout=30 to the call in a real program: requests waits forever by default.

What the converter understands

The address, -X, -H, -d and its variants, --json, -u, -A, -b, -e, -G and -I, quotes and lines continued with a backslash. Options that do not change the request, such as -L, -s or --compressed, are ignored.

Other languages

curl to JavaScript, curl to PHP, curl to Go, curl to Java, or all eight languages at once.

Need pages for a program, not code? gimmepage fetches any public page in one request: 1 credit a page, failed requests free.