Curl to Code
Turn a curl command into Python requests, JavaScript and PHP code — headers, body, method and basic credentials carried across.
Every API doc on earth still speaks curl first, and every project needs that same request in its own language. The translation looks trivial and is not: a shell command is a quoted, escaped, flag-laden string, and converting it means tokenising it the way a shell does before any code can be written. This page does exactly that. Worked example: the command curl -X POST https://api.example.com/v1/items -H ’Content-Type: application/json’ -H ’X-Key: abc’ -d ’{"a":1}’ parses to method POST, the URL exactly as written, a headers map whose Content-Type is application/json, and the data string {"a":1} — and the Python output for it is a requests.post call carrying that URL, those headers and that body. A bare curl https://example.com, with no flags at all, parses to a plain GET with no body, which becomes requests.get and a one-argument fetch call.
The command you paste stays in page memory on your device: it is never uploaded, stored or put into a link — which matters, because pasted commands often carry live API keys and session headers. Check any key in the output before you commit the converted code anywhere.
Quick answers
How do I convert a curl command to Python?
Paste the command and copy the Python block: it uses the requests library, with the method as the verb (requests.post for a POST), the URL verbatim, headers as a dict, the body as a data string, and -u credentials as an auth tuple.
The same paste also produces JavaScript fetch code and PHP curl code, all parsed from one tokenisation of the command.
How does the converter read quoted arguments?
Like a shell: single-quoted text is literal, double-quoted text processes backslash escapes, a backslash outside quotes escapes the next character, and a backslash at the end of a line joins the next line — so commands copied from docs and terminals parse as written.
Check the parsed summary line after pasting; it shows the method, URL, header count and body the converter actually found.
How to use
- Copy a curl command from your terminal history, a browser’s “Copy as cURL” menu, or an API doc, and paste it here. Quoting is honoured exactly as a shell would: single quotes are literal, double quotes allow escapes, and backslash line continuations join up.
- Check the parsed summary first — method, URL, header count and whether a body was found. If the summary is wrong, the generated code will be too, and the fix is in the pasted command.
- Copy the language you need: Python uses the requests library, JavaScript uses the standard fetch API available in browsers and Node, and PHP uses its curl extension.
- Replace any real API key or session header in the copied code before you commit it. The converter carries credentials across faithfully — that is its job — so the secret hygiene afterwards is yours.
About this tool
The flags understood cover the working set of real-world commands: -X/--request for the method, -H/--header (split on the first colon, so values may contain colons), -d/--data and its --data-raw, --data-binary and --data-urlencode spellings (any of them implies POST when no method was given, exactly as curl behaves), -u/--user for basic credentials, --url, and the header shortcuts -A, -e and -b for user agent, referer and cookie. Output-only flags such as -o are consumed so their arguments are never mistaken for the URL. What is deliberately not reproduced: curl’s own runtime behaviour — retries, redirects, TLS options and output formatting are command-line concerns, and the generated code uses each language’s normal defaults instead, stated here rather than silently approximated. The command you paste never leaves the page, which matters because pasted commands so often carry live keys.
Frequently asked questions
Which curl flags are supported?
Method (-X/--request), headers (-H/--header), bodies (-d/--data, --data-raw, --data-binary, --data-urlencode, --data-ascii), basic credentials (-u/--user), an explicit --url, the -A/-e/-b header shortcuts, and output flags like -o whose arguments are skipped safely. Anything else is ignored rather than guessed, and the parsed summary shows what was actually understood.
Why does a command with -d become a POST?
Because that is what curl itself does: sending a body with -d implies POST unless -X says otherwise. The converter mirrors curl’s rule, so code converted from a working command behaves like the command.
The header value contains a colon — is it split correctly?
Yes. Headers are split on the first colon only, so a header like Authorization: Bearer a:b:c keeps its full value. The parsed summary and each generated block use the same split.
Is my pasted command sent anywhere?
No. Parsing and code generation happen in this page on your device. Nothing is uploaded, stored or put into a link — a deliberate design, because curl commands routinely embed API keys, cookies and session tokens.
First time embedding? Read the step-by-step guide →
More free tools
UUID Generator
Generate random v4 UUIDs in bulk.
JSON Formatter & Validator
Format, minify and validate JSON in one click.
What Is My IP
See your public IP address instantly. No sign-up, nothing stored.
Regex Tester
Test, check and validate regular expressions with live highlighting.
JWT Decoder
Decode a JWT token without the secret — see its header and payload.
SHA-256 Hash Generator
Generate SHA-256 / SHA-512 hashes instantly.