My Tool Studio
Developer Tools·5 min read

How to Convert cURL to Python, Fetch, or Axios

Every API doc gives you a curl example, and almost no project actually ships curl. Sooner or later you need that request as Python for a script, fetch for the browser, or axios for a Node service. You can translate it by hand, flag by flag, or paste the command into the cURL to Code Converter and pick the language you need from 19 targets, Python, fetch and axios among them. This guide walks through a conversion, the flags that change the output, and the details worth checking before generated code goes anywhere near production.

.curl.codeCURL → CODE

Why curl commands keep landing in your clipboard

The universal request format nobody deploys.

API documentation has standardized on curl. Stripe, GitHub, OpenAI, and nearly every internal wiki present endpoints as a curl one-liner, because it runs anywhere and spells out the entire request. That's great for testing and useless for shipping. Your actual codebase speaks JavaScript or Python, and retyping headers by hand is exactly where typos creep in.

The same thing happens inside teams. A colleague reproduces a bug, posts the failing command in Slack, and now you want that precise request inside a unit test. Translating it mechanically, flag by flag, is the boring kind of work a tool should do for you.

From DevTools Copy as cURL to code you can commit

Capturing a real browser request in two clicks.

Open the Network panel in Chrome, Firefox, or Edge, right click any request, and choose Copy as cURL. The browser hands you the complete request: method, URL, every header, cookies, and the body. On Windows either version works: the cmd version escapes quotes with carets, and the parser strips them before reading the command. Paste it into the curl command box and the code fills in immediately; press Python requests, fetch or any other language to switch. Backslash line breaks and the $'...' strings Chrome produces are handled.

One warning about this workflow: DevTools copies everything the browser sent, including a pile of sec-fetch and cookie headers your script doesn't need. Delete the noise in the input box and watch the generated code shrink in real time, since the output updates as you type.

How to convert cURL to Python requests, worked through

A small authenticated GET, start to finish.

Take this command: curl https://api.example.com/v1/orders -H "Authorization: Bearer sk_test_51abc" -H "Accept: application/json". Paste it in and press Python requests.

The output imports requests, builds a headers dictionary with both entries, then calls requests.request("GET", "https://api.example.com/v1/orders", headers=headers) and prints res.status_code and res.text. A few lines, ready to run. The fetch output sends the same headers and, because Accept asks for JSON, reads the response with res.json().

Notice what the converter decided for you. There was no -X flag and no body, so the method stayed GET. Each -H pair became one entry in the headers dictionary. Had the command carried -d item=42, the method would flip to POST, the body would appear as data=, and the converter would add a Content-Type: application/x-www-form-urlencoded header, because that's what curl sends by default. Had the body been JSON with a JSON Content-Type, Python would get json=payload instead, and fetch would get JSON.stringify around a real object.

Reading curl flags so you can sanity-check the output

Four flags cover most commands you'll meet. -X, or --request, sets the HTTP method. -H, or --header, adds one header per use. -d, along with --data, --data-raw, and --data-binary, attaches a request body. And -u sets Basic authentication: fetch gets a computed Authorization header, axios gets its auth option, and Python gets auth=(user, password).

Beyond those, the converter reads --json, --data-urlencode, -F form fields and file uploads, -b cookie strings, -A and -e for User-Agent and Referer, -G to move data into the query string, -I for HEAD, and -k for skipping certificate checks. It also maps -L, -m or --max-time, -x and --compressed to each library's redirect, timeout, proxy and decompression options. Flags that don't change the request, such as -s and -v, are ignored, and options like -o are skipped along with their values. Knowing this list helps you spot when a command depends on behavior outside the request itself.

Conversion slip-ups that produce broken requests

Most failed conversions trace back to one of a handful of habits:

  • Assuming every flag carried over. A -b that names a cookie file instead of name=value pairs is dropped, and output or timing options never reach the code.
  • Missing the silent GET to POST switch. Sending data with -d, --json or -F implies POST in curl, and the generated code mirrors that even though you never typed -X POST.
  • Pasting the cmd version of Copy as cURL. Its caret-escaped quotes confuse the parser, so copy the bash version even on Windows.
  • Leaving file placeholders in place. A field like -F avatar=@photo.jpg becomes fileInput.files[0] in the browser JavaScript output, which you replace with your own file object.
  • Committing credentials. The Bearer token from your paste lands verbatim in the output, so move it into an environment variable before the snippet leaves your machine.
  • Shipping -k by accident. Python gets verify=False, Go and C# get their insecure settings, and fetch gets a comment. Skipping certificate checks belongs in local testing only.

Getting more from the cURL to Code Converter

Convert one canonical command per endpoint, then parameterize it in your own code, rather than converting a dozen variations of the same request. The parsing is deterministic, so identical input always yields identical output, which keeps diffs clean when an API doc changes and you re-convert.

Check the scheme, too. A command without http:// or https:// gets http:// added, which is what curl does, so change it if the server expects a secure connection. Before pointing generated code at production, run it against an echo service and compare what arrives with what the original command sent. Thirty seconds of verification beats an afternoon spent hunting a header that got trimmed.

When a teammate works in another stack, you don't need a second tool. The same command produces Go, Java, C#, PHP, Ruby, Rust, Swift, Kotlin, Dart, PowerShell, HTTPie and wget versions from the language menu, and Download saves the code with the right file extension. The raw HTTP output is useful in bug reports, because it shows exactly what goes over the wire.

Where conversion ends and inspection begins

This converter translates requests; it doesn't look inside them. When the copied command carries a Bearer token, paste that token into the JWT Decoder to see its claims and expiry before you build tests around it. If a -u flag produced a Basic Authorization header, Base64 Decode and Encode shows exactly what got encoded. And when the request runs but the response surprises you, the HTTP Status Codes List explains what the number coming back is trying to tell you.

Try it now

Open cURL to Code Converter

The tool is one click away. No sign up, no upload, no payment.

Open cURL to Code Converter