cURL to fetch and Python converter

Convert a curl command into JavaScript fetch or Python requests code.

Runs in your browser. Your input is not uploaded.

What it does

API docs usually give examples as curl commands. This converter reads the command and writes the same request as JavaScript fetch or Python requests, including headers, body, form fields and basic auth.

Shell quoting and \ line continuations are handled, so you can paste a multi-line command from documentation or from the browser’s “Copy as cURL”.

How to use it

  1. Paste a curl command.
  2. Choose fetch or Python.
  3. Copy the code. Options that have no equivalent are listed under it.

Example

Input
curl -X POST https://api.example.com/items -H 'Content-Type: application/json' -d '{"name":"a"}'
Output
const response = await fetch("https://api.example.com/items", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "name": "a"
  }),
});

Things to watch for

  • curl does not follow redirects unless -L is given. fetch always follows them, and the Python output sets allow_redirects=False to match curl.
  • Browser “Copy as cURL” includes cookies and auth headers. Remove them before sharing the code.
  • -k (skip TLS verification) becomes verify=False in Python and cannot be done with fetch.

Questions

Which curl options are supported?
-X, -H, -d and its variants, --json, -F, -u, -G, -I, -L, -k, -A, -e and -b. Others are listed as ignored.
Is the command sent anywhere?
No. It is parsed in this page, so tokens in it stay on your machine.
Does it handle Windows cmd syntax?
No. It reads POSIX shell quoting. Use the bash version of “Copy as cURL”.
Why does -d make it a POST?
curl switches to POST when data is given without -X. The converter does the same.