cURL to Code: Convert curl to Swift, fetch or Python
Turn a curl command into Swift URLSession, JavaScript fetch or Python requests code on Mac, see which flags convert, and where to go for other languages.
GuideUpdated 9 min read
On this page
To convert a curl command to code on a Mac, paste it into a converter and pick a target language. macOS has no built-in tool for this. The quickest offline route is the cURL → Code tool in Bytepliers: paste the command, choose Swift URLSession, JavaScript fetch or Python requests, and copy the result.
Bytepliers writes only those three languages. For Go, PHP, Kotlin, Rust, C# and many others, curlconverter is free and covers 29 languages in total.
Converting runs entirely on your Mac. Nothing is sent to the server unless you click Run.
When converting a curl command helps
API docs and teammates often share requests as curl commands. A curl line is easy to test in Terminal, but your app needs the same request as code. Writing it by hand is where mistakes happen: a header gets dropped, a JSON body loses its escaping, or form data is encoded the wrong way.
A converter reads the method, URL, headers, body and auth from the command and writes them out as code. You then add what your app needs on top, such as error handling, decoding and retries.
Flags Bytepliers reads
cURL → Code parses these curl options:
| Flag | What it means in curl |
|---|---|
-X | Sets the HTTP method (POST, PUT, DELETE…) |
-H | Adds a request header |
-d | Sends data as the request body |
--data-raw | Like -d, but @ has no special meaning |
--data-binary | Sends the data exactly as given |
--data-urlencode | URL-encodes the data before sending |
--json | Sends a JSON body with JSON content headers |
-F | Adds a multipart form field |
-u | Username and password for basic auth |
-A | Sets the User-Agent header |
-e | Sets the Referer header |
-b | Sends cookies |
-G | Moves -d data into the URL query string and uses GET |
-I | Makes a HEAD request |
-L | Follows redirects |
-k | Skips the TLS certificate check |
--compressed | Asks for a compressed response |
--url | Gives the URL explicitly |
It also handles the ways commands usually arrive when you copy them:
- single and double quotes, and
$'…'strings \line continuations (macOS and Linux shells) and^continuations (Windows Command Prompt)--option=valuesyntax and combined short flags
The tool also shows a request summary: method, URL, headers, body size and form fields. Any options it didn't translate are listed there too. Check that list after each conversion, because it shows what the generated code leaves out for that command.
Convert a curl command to code in Bytepliers
- Copy the curl command.
- Open Bytepliers and choose cURL → Code in the Convert group of the sidebar. You can also press ⌘K (Command-K) and type "curl".
- Paste the command into the curl command pane, or drop a text file containing it onto the pane.
- Choose an output tab: Swift URLSession (the default), JavaScript fetch or Python requests.
- Check the request summary for untranslated options.
- Press ⇧⌘C (Shift-Command-C) to copy the code, or choose Save… (⌘S, Command-S) to save it to a file.


To see a converted example before using your own command, click Sample in the toolbar.
Faster ways to get Swift code
If you write Swift, you can skip the window. Detect & Replace and the Services menu both turn a curl command straight into Swift URLSession code:
- Detect & Replace Clipboard: copy the command and press ⌥⇧⌘B (Option-Shift-Command-B). The clipboard now holds Swift code. To get the curl command back, choose Tools ▸ Restore Previous Clipboard.
- Services: select the command in another app and choose Services ▸ Transform with Bytepliers from that app's menu. The selection is replaced in place and the clipboard is not touched. If the item doesn't appear, open System Settings, search for "Keyboard Shortcuts" and check that it's turned on in the Services list.
- Quick Panel: with the command copied, press ⌥⌘B (Option-Command-B) to preview the Swift code, then press Return to copy it.
Let Bytepliers spot curl commands for you
Bytepliers can recognise a curl command on the clipboard. To turn this on, go to Settings ▸ General ▸ Clipboard and set Clipboard matches: to Suggest Tools. The next time you switch to Bytepliers with a curl command copied, a chip offers cURL → Code.
The setting is off by default. With it off, Tools ▸ Check Clipboard (⇧⌘K, Shift-Command-K) runs the same check when you ask. On macOS 15.4 or later, automatic checks are skipped if Bytepliers' paste access is set to Ask or Deny. ⇧⌘K still works.
Run the request before you convert it
If the generated code fails, it helps to know whether the request itself works. In cURL → Code, click Run or press ⌘↩ (Command-Return). The same Open URL or cURL sheet opens from JSON Formatter with ⌘U.
- Click Run.
- The first time you contact a host, Bytepliers asks "Send requests to
<host>?" Confirm, and it won't ask again for that host. - The sheet shows the status, timing, size and body. Use Show response headers to see the headers.
- If the body is JSON, press Return for Open in JSON Formatter to browse it as a tree or filter it with jq.


What the request sends and how it behaves:
- It goes straight from your Mac to the server, and only when you click.
- The session is ephemeral: no stored cookies, no saved credentials, no cache. The only credentials and cookies sent are the ones in your command's
-u,-band-Hoptions. If the server asks for authentication, the challenge is rejected. -Ftext fields are sent as multipart form data.@filereferences are refused.- Redirects on the same host are followed. A redirect to a different host, or from https to http, stops at "Redirects to … · Follow" so you can decide.
-kasks "Connect without checking the certificate?" every time.- A request times out after 30 seconds, with a 120-second limit for the whole transfer. Response bodies are capped at 50 MB.
- Nothing from the request is saved to history.
Convert from the command line or Shortcuts
The bytepliers command
Install it from Settings ▸ Integrations ▸ Command-Line Tool ▸ Install…. Bytepliers must have been opened at least once for the command to run. Each language has its own transform: curl-to-swift, curl-to-fetch and curl-to-python.
pbpaste | bytepliers curl-to-pythonReads the copied curl command from the clipboard and prints Python requests code.
pbpaste | bytepliers curl-to-swift | pbcopyReplaces the clipboard with Swift URLSession code. Copy the curl command again if you need it back.
bytepliers curl-to-fetch -i request.curlReads the command from a file and prints JavaScript fetch code.
The command works with the app closed and makes no network requests. Exit status 77 means it needs a license or an active trial. The command-line docs list every option.
Shortcuts and recipes
In the Shortcuts app, add the Transform Text action and set Transform to cURL → Swift, cURL → fetch or cURL → Python. Feed it the output of Get Clipboard, then pass the result to Copy to Clipboard.
If you convert to Python or fetch all the time, save a recipe. In Pipelines, choose Add Step ▸ Convert ▸ cURL → Python (or cURL → fetch), then Save As…. The recipe then appears in ⌘K, in the menu bar's Run Recipe on Clipboard list and in Quick Panel type-ahead. See Shortcuts, Services, Raycast and Alfred and pipelines and recipes for setup details.
Other curl to code options: curlconverter, DevUtils, Postman, Insomnia
We make Bytepliers, so weigh our view accordingly. We've tried to be fair to the other tools.
| Tool | Output languages | Where it runs | Price (as of November 2026) |
|---|---|---|---|
| Bytepliers cURL → Code | Swift URLSession, JavaScript fetch, Python requests | Native Mac app, offline; plus CLI, Shortcuts, Services | Part of MacSuite, $349 one-time |
| curlconverter | Python, JavaScript and 27 other languages | Website and command-line tool | Free, open source |
| DevUtils | 15 languages | Native Mac app | From $29 one-time for 1 Mac, with 1 year of updates |
curlconverter covers most of the languages Bytepliers doesn't. Its outputs include C, C#, Go, Java, Kotlin, PHP, PowerShell, R, Ruby and Rust. It also offers several library variants per language, such as node-axios, node-got and java-okhttp. On the command line, you pick the output with --language. It only converts curl and has no native Mac app. If a command contains a live token, decide whether you'd rather paste it into a website or run the command-line version.
DevUtils is a native Mac toolbox whose curl converter covers 15 languages. If you regularly need a language other than Swift, JavaScript or Python and prefer a Mac app to a website, check whether DevUtils covers it. We compare the two apps in Bytepliers vs DevUtils.
Postman and Insomnia are full API clients, not dedicated converters. Choose one of them if you need to keep, organise and re-test requests over time. Insomnia is open source, has a free Essentials tier, and supports REST, GraphQL, gRPC, WebSockets and Server-Sent Events. Postman has native apps for Intel and Apple silicon Macs.
Options that don't convert
Options outside the flag list above aren't converted. Check the request summary's untranslated list to see which ones affect your command. Common examples:
- Output and logging flags such as
-s,-vand-ocontrol what curl prints or saves. They usually don't matter in app code. - Timeouts and retries such as
--max-timeand--retryhave to be added by hand. In Python requests, passtimeout=. In URLSession, set the request'stimeoutInterval. - Proxies and client certificates such as
-xand--certdepend on how your app is configured, so set them up in your own code. - Bodies read from files (
-d @payload.json): Run refuses@file, so paste the body into the command if you want to test the request first.
A parsed flag may still have no direct equivalent in every output language. For each command, the summary is the place to check.
If it doesn't work
- "The command must start with curl": you copied a prompt or extra text along with the command, such as
$or a comment. Delete everything beforecurl. - "No URL found in the command": the URL is missing or was cut off when you copied a multi-line command. Copy the whole command again.
- "Unterminated single quote": a quote isn't closed. Usually a long command was truncated, or a body contains an unescaped apostrophe. If the body needs a literal
', use a$'…'string. - "Missing value for …": a flag has no value, for example a trailing
-H. Add the value or remove the flag. - "Input is … — the limit for live conversion is 2 MB.": the command has a very large inline body. Trim the body, convert the request, then load the body from a file in your code.
- Run fails:
- "The server's certificate isn't trusted" means a self-signed or untrusted server. Add
-kand confirm when asked. - "Plain http isn't allowed for this host; use https" means you should switch the URL to https.
- "The host couldn't be found" or "This Mac is offline" points to a typo in the URL or a network problem.
- "The request timed out after 30 s" usually means the server is slow or can't be reached from your network.
- "The server's certificate isn't trusted" means a self-signed or untrusted server. Add
Bytepliers is part of MacSuite. You can try it free for 7 days.
FAQ
Does converting a command send the request? No. Conversion happens on your Mac with no network access. Only Run sends the request, and only after you click it.
Will an API token in my curl command end up in history? History stays on your Mac. Bytepliers doesn't record inputs that look like secrets, such as text with bearer tokens, Authorization or Cookie header lines, URL credentials or common API key formats. You can change this with Also record inputs that look like secrets in Settings ▸ History. Anything it doesn't recognise as a secret is recorded as usual. To stop that, turn off Remember recent inputs per tool or delete the entry from the tool's History popover.
Can Bytepliers convert Python or fetch code back into curl? No. It converts only from curl, and only to Swift URLSession, JavaScript fetch and Python requests.
What do I do with the JSON response? Open it in JSON Formatter from the Run sheet. To generate Swift types from it, see Generate Swift Codable structs from JSON. For other ways to tidy it up, see how to format JSON on Mac.