Utilo

curl to Python Converter – Free, Online, Private

Turn a curl command into a Python requests call, with a headers dict and a json= payload when the body is JSON.

Input
Output

How to convert curl to Python

  1. Paste a curl command that starts with curl.
  2. Copy the requests snippet. Import requests is included.
  3. Install requests in the environment where you will run it. This page does not run the request.

requests, not urllib

The output imports requests and calls requests.post, requests.get, or requests.request for unusual methods. Headers are a dict. A JSON body is assigned to a payload variable and passed with json=, which also sets the content type, so a redundant Content-Type header copied from curl is dropped to avoid a duplicate. A non-JSON body uses data=. Basic auth uses the auth= tuple. An insecure curl flag becomes verify=False, with the same warning you would give yourself in code review. Multipart fields use data or files.

Shell details

The tokenizer understands single quotes, double quotes, and $'...' ANSI-C quoting, plus backslash line continuations. A URL that was quoted in the shell is unquoted in the Python string. Environment variables such as $TOKEN are not expanded, because this page is not a shell. They remain the characters $TOKEN unless you already pasted the secret. That is the safer default. File paths in -d @file are not read. The Python curl converter on the main Utilo tool can also go the other way for some snippets.

Worked example

The sample becomes import requests, a headers dict with the bearer token, a payload dict with name and role, and requests.post(url, headers=headers, json=payload). The response status and body are printed. You still need network permission and a real token. The snippet does not create a session or retry. Add those in the client you already use. If the API wants a raw string body rather than a JSON object, remove the content type and the converter will emit data= instead.

Do not run secrets you do not understand

A pasted command can send a token to a host. Generating Python does not perform the request, which keeps an accidental click from replaying it. Read the URL before you run the snippet. Nothing is uploaded to build the Python.

Frequently asked questions

Which HTTP library?

requests. The import is at the top of the snippet. httpx is not generated.

Does json= replace the body?

When the body parses as JSON and the content type says JSON, the snippet uses json=payload. Otherwise it uses data=.

Are environment variables expanded?

No. $TOKEN stays $TOKEN. Expand it in a shell before pasting if you really want the value in the snippet.

Is the command uploaded?

No. Parsing is local.