TapCub is live — analytics, insights and live chat, free on one platform

cURL converter · Python cURL to Python: convert curl commands to requests

Paste a curl command from API docs or your browser and get Python code that uses the requests library: the right method, a headers dict, json= for JSON bodies, data= for forms, files= for uploads, plus auth, cookies, verify and timeout.

  • requests library
  • Bash and cmd quoting
  • Parsed locally

Convert curl to Python requests

The output language is set to Python. Paste your own command; the code updates as you type.

Converter

Line breaks with \ (bash), ^ (cmd) or ` (PowerShell) are fine. Variables like $TOKEN are kept as text.

Parsed a POST request to api.pathclue.com.

Checks

  • WarningContains credentials (Authorization). They stay in this page, but remove them before sharing the code or committing it; load them from environment variables instead.
Code
import requests

headers = {
    'Authorization': 'Bearer wck_…',
}

json_data = {
    'events': [
        {
            'event': 'purchase',
            'login_id': 'u_123',
            'insert_id': 'order-1001',
            'properties': {
                'revenue': 19.9,
            },
        },
    ],
}

response = requests.post(
    'https://api.pathclue.com/api/v1/track',
    headers=headers,
    json=json_data,
)
print(response.status_code)
print(response.text)

Parsed request

What the command sends, so you can check the conversion.

PartValue
MethodPOST
URLhttps://api.pathclue.com/api/v1/track
Header AuthorizationBearer wck_…
Header Content-Typeapplication/json
BodyJSON
Runs entirely in your browser. Nothing you type here is uploaded or stored by TapCub.

Version v1.0Updated Update history

Read the result

Check the conversion in three places

Code that looks right can still send a different request. These are the parts worth a second look.

Parsed request

The table under the code lists the method, URL, every header and the body type exactly as curl would send them. If something is missing there, the command was cut off or quoted differently than you think.

Method

curl switches to POST when you add -d or -F, and to GET with -G. The sample has an explicit -X POST, so the code uses POST either way.

Body type

A JSON body becomes a native object (json= in Python, JSON.stringify in JavaScript, an array in PHP), so you can edit it as data. Form data becomes field pairs; -F becomes a multipart upload.

Checks

Warnings flag credentials in the command, disabled certificate checks, files the code has to read, and options that could not be converted.

The sample key wck_… is the placeholder from our docs, which is why the credentials warning appears. A real key would trigger the same warning.

How to use it

Three steps

Nothing is run and nothing is sent.

  1. 1

    Copy the command

    From API docs, a terminal, or your browser: in the Network tab, right-click a request and choose Copy as cURL (bash or cmd both work).

  2. 2

    Pick the language

    fetch for front-end code, Node.js for scripts and servers, or Python, PHP, Go or Java.

  3. 3

    Copy and clean up

    Copy the code, move tokens and cookies into environment variables, and remove browser-only headers you do not need.

Supported options

What the converter understands

The parser follows the curl manual. Options that only change curl’s own output (-s, -v, -o, -i) are ignored because they do not change the request.

  • Quoting: single and double quotes, $'…', backslash escapes and line continuations in bash; ^ in Windows cmd; backtick in PowerShell
  • Short options can be combined (-sSL) or attached (-XPOST)
  • Without a scheme, a URL gets http://, as curl does
curl options and how they are converted
curl optionMeaningIn Python requests
-X, -I, -GMethod; HEAD; data goes into the query stringrequests.post(…), requests.head(…), query appended to the URL
-H, -A, -eHeader; User-Agent; Refererheaders={…}
-d, --data-raw, --data-binary, --data-urlencodeBody, form-encoded by defaultdata={…} or data='…'
--json, or -d with a JSON Content-TypeJSON bodyjson={…}
-F, --form-stringmultipart/form-data, @file uploads a filefiles={…}
-u, -bBasic auth; cookiesauth=(…), cookies={…}
-L, -k, -m, --compressedFollow redirects; skip TLS checks; timeout; accept gzipFollowed by default, verify=False, timeout=, automatic
Worked example

One request, six languages

How the sample command (a JSON POST with a bearer token) is written in each language.

The sample curl command converted to six languages
LanguageRequest callJSON bodyHeaders
JavaScript (fetch)await fetch(url, { method: 'POST', … })body: JSON.stringify({…})headers: {…}
Node.jsSame as fetch (built in since Node 18)body: JSON.stringify({…})headers: {…}
Pythonrequests.post(url, …)json=json_dataheaders=headers (Content-Type left to requests)
PHPcurl_setopt_array($ch, […])CURLOPT_POSTFIELDS => json_encode([…])CURLOPT_HTTPHEADER
Gohttp.NewRequest("POST", url, body)strings.NewReader(`{…}`)req.Header.Set(…)
JavaHttpRequest.newBuilder().POST(…)BodyPublishers.ofString("…").header(…)

Redirects differ by language: curl follows them only with -L. fetch, requests and Go follow by default; PHP cURL and Java HttpClient do not, so the code turns following on only when the command has -L.

Common mistakes

Why converted code behaves differently

Most differences come from the environment, not from the conversion.

Browser-only headers

A command copied from Chrome carries Cookie, User-Agent, sec-ch-ua and similar headers. Browsers refuse to set some of them from fetch, and servers may reject a stale session cookie. Keep only what the API needs.

Tokens pasted into code

Bearer tokens, API keys and session cookies end up in source control easily. Read them from environment variables, and rotate any key that was shared.

CORS in the browser

curl ignores CORS; a browser does not. If the API does not allow your site’s origin, the fetch version fails where curl worked. Call it from your server instead.

Shell variables and files

$TOKEN and @body.json are expanded by the shell or by curl. The code keeps $TOKEN as text and reads @file where it can; replace them with real values.

FAQ

cURL converter questions

Still have a question?

Chat with the team behind TapCub — we usually reply within a few hours on business days.

How do I convert curl to Python requests?

Paste the curl command above. The code uses requests.post, requests.get and so on, with the headers in a dict and the body in json=, data= or files= depending on what curl sends. Install the library with pip install requests.

When does the code use json= and when data=?

If the Content-Type is JSON (or the command uses --json) and the body parses as JSON, the body becomes a Python dict passed as json=, and requests sets the Content-Type itself. Form fields become a dict in data=; any other body is passed as a string in data=.

How are -u, -b and -k converted?

-u user:pass becomes auth=('user', 'pass'), cookies from -b become a cookies= dict, and -k becomes verify=False, which you should remove outside testing.

Why does Python follow a redirect that curl did not?

requests follows redirects by default for every method except HEAD; curl follows them only with -L. Add allow_redirects=False to the call to get curl’s behaviour.

How is a file upload with -F converted?

-F "file=@photo.jpg;type=image/jpeg" becomes an entry in files= with the file name, an open file handle and the content type; plain -F name=value fields go in the same dict as (None, value), which is how requests sends text parts.

Changelog

Update history

New features, fixes and data refreshes for this tool, newest first.

  1. · v1.0

    LaunchedFirst release.

Missing something or found an error? Tell us — requests that come up often go into the next update. All tool updates

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics