cURL to Python converter

Paste a curl command and get the same request as Python code that uses Requests, with a note for any option it does not carry over. The command stays in your browser.

Example command: paste your own over it

Python
  • Content-Type: application/json is left out of the headers: json= sets it.
  • Left out, because they only change what curl prints: -s.

Fetching web pages from Python? The Web Page to Markdown API returns a page's content as Markdown, without its menus, in one request.

Free, no sign-up. It runs in your browser: what you type is not sent anywhere.

Checked on 2026-11-24.

How to convert curl to Python

Paste the curl command into the box. The Python version appears underneath at once, with a list of notes: what was left out and why, and where the code does something slightly different from curl. Copy it, or download it as a .py file. The menu at the top switches the output to JavaScript.

The command can be written for bash or zsh, with single quotes, double quotes, $'…' strings and lines continued with a backslash. A command written for the Windows command prompt, with ^ at the ends of lines and ^" around values, is read by that shell's rules instead, and a backtick at the end of a line, as PowerShell continues lines, is accepted too. The tool does not send the request and has no way to: it only rewrites the text, and your browser does all of it.

A request copied from a browser is a good start: in Chrome's developer tools, the Network panel's menu for a request has Copy as cURL. If the command carries cookies or an Authorization header, they let anyone who has the code act as you on that site, so keep the converted code as private as a password.

What each option becomes

The meaning of each option is taken from curl's manual (the version for curl 8.23.1), and the Python from the Requests documentation.

OptionWhat curl doesPython code
-X, --requestChanges the method word, and only thatrequests.put(…), or requests.request('PROPFIND', …) for other words
-H, --headerAdds a header; one with the name of a header curl would send replaces itheaders={…}
-d, --dataSends a POST with Content-Type application/x-www-form-urlencoded; several are joined with &; @file reads a file and strips its line breaksdata={…} for name=value pairs, else data='…' and that Content-Type
--data-rawThe same, but @ has no special meaningAs -d
--data-binarySends the data "exactly as specified"; @file keeps line breaksAs -d; a file is read with open(…, 'rb')
--data-urlencodePercent-encodes content, =content or the content of name=contentDecoded into data={…}, which Requests encodes again
--jsonSends the data as it is, with Content-Type and Accept application/json (added in curl 7.82.0)json=… and an Accept header
-G, --getPuts the data in the address as a query string and sends a GETparams={…}
-u, --userUser name and password; Basic authentication is curl's defaultauth=('user', 'password'); with --digest, HTTPDigestAuth
--oauth2-bearerA bearer tokenAn Authorization: Bearer … header
-A, -eUser-Agent and RefererHeaders
-b name=valueCookies; without = it is a file to read cookies fromcookies={…}
-I, --headA HEAD requestrequests.head(…)
-k, --insecureSkips the certificate checkverify=False
-m, --max-timeThe longest a transfer may take, in secondstimeout=…
-x, --proxyA proxyproxies={…}
-s, -v, -i, -w…Change what curl printsLeft out

Some details follow from those two sources. Requests sets Content-Type: application/json itself when you pass json=, so the converter leaves that header out of headers; with data= and a string it sets no Content-Type, so the converter writes the one curl would send. When the command sets its own Authorization header, curl sends it instead of the -u credentials, while in Requests the auth= parameter would win; the converter keeps the header and leaves auth= out, so the server sees what curl would have sent.

Where the code behaves differently from curl

  • Redirects. curl follows a redirect only with -L. Requests "will perform location redirection for all verbs except HEAD", its Quickstart says, so the code follows redirects whether or not the command had -L. Add allow_redirects=False if you need curl's default.
  • Timeouts. The Requests documentation says "Nearly all production code should use this parameter in nearly all requests", because without it a request can wait for ever. The code always has timeout=: the --max-time value, or 30 seconds. They do not measure the same thing: --max-time limits the whole transfer, while Requests' timeout "is not a time limit on the entire response download" but the longest wait for the server.
  • Certificates. -k becomes verify=False. The Advanced Usage page warns that this makes the program "vulnerable to man-in-the-middle (MitM) attacks"; keep it for local testing.
  • Repeated headers. A Python dict holds one value per name. When the command gives a header twice, the code sends only the last, and a note says so.
  • Compression. --compressed is left out: Requests decodes gzip and deflate answers by itself.

What it does not convert

Each of these gets a note in the tool when your command uses it, so nothing is dropped without a word:

  • Multipart forms and uploads. -F (a multipart form, often with a file) and -T (a file upload) are not converted.
  • Files curl reads or writes. -b with a file name, -c (a cookie jar), -K (a config file), --data-urlencode name@file, -o and -O.
  • Connection details. Client certificates, --resolve, --connect-to, --retry, HTTP/2 and HTTP/3 options, rate limits and Unix sockets.
  • The shell. Variables such as $TOKEN are written as they are, not filled in, and only the curl command is read: anything after a pipe, ; or && is left out. curl's own globbing, {a,b} and [1-9] in an address, is not expanded.
  • Several addresses. Only the first is converted.

Get the data automatically

Every endpoint's reference page shows its request three ways: as curl, as JavaScript and as Python. The page content endpoint, for example, which returns one web page's content as Markdown or text, has this curl line:

Terminal
curl "https://pipefetch.com/v1/web/content?url=https%3A%2F%2Fdocs.apify.com%2Facademy" \
  -H "x-api-key: YOUR_API_KEY"

The same request in Python, with the key read from the environment, a timeout, and the answers that cost nothing:

Python
import os
import requests

res = requests.get(
    "https://pipefetch.com/v1/web/content",
    params={"url": "https://docs.apify.com/academy", "format": "markdown"},
    headers={"x-api-key": os.environ["PIPEFETCH_API_KEY"]},
    timeout=90,
)
if res.status_code == 404:
    # not_allowed, needs_javascript, no_content, page_not_found, website_blocked
    # or website_unreachable: not charged
    print(res.json()["error"]["code"])
else:
    res.raise_for_status()
    page = res.json()["data"]
    print(page["title"], page["wordCount"], "words")
    print(page["content"])

Pasted here, that line gives the same request with the key written into the code; in a script, read it from the environment instead, as above. A request costs 1 credit, and none of the 404 answers costs anything. The page is read as plain HTML without running JavaScript, so a page that builds its text in the browser comes back with needsJavaScript true.

Questions

Is my curl command sent anywhere?

No. The command is turned into Python by this page, in your browser, and the request in it is never made. Nothing you paste leaves the page, which matters because a copied command often holds a token, a password or session cookies.

Why is Content-Type missing from the Python headers?

Because the code sends JSON with json=, and Requests then sets Content-Type: application/json itself. Writing it in headers as well would change nothing.

Why does the code have timeout=30 when my command had no timeout?

Requests waits for ever unless it is given a timeout, and its documentation says nearly all production code should set one. The converter uses your --max-time when there is one, and 30 seconds otherwise. Change it to suit the server.

Can I paste a command copied from Chrome?

Yes. Chrome's developer tools have Copy as cURL in the Network panel, and the tool reads commands written for bash and for the Windows command prompt. If the command carries cookies or an Authorization header, keep the converted code private.

Why does the Python code follow redirects when curl did not?

curl follows redirects only with -L, while Requests follows them by default for every method except HEAD. Add allow_redirects=False to the call to behave like curl without -L.

What about curl -F?

Multipart forms are not converted, and the tool says so in a note. In Requests, a form with files is sent with files=, as the Requests Quickstart shows.

Need this for many accounts, or in your code? The Pipefetch API returns the data as JSON, one GET request at a time. Get an API key with 100 free credits, no card needed.

APIs that return this data

Guides

Similar tools

More free tools

All free tools