Code converters

cURL to Python Requests Converter

Paste a cURL command and get idiomatic Python, with headers, params, cookies and the body split into the arguments requests and httpx expect.

  • Free foreverNo trial, no paywall, no usage limits.
  • No sign-upOpen the page and start. We never ask for an email to use a tool.
  • PrivateEverything runs in your browser. Your input is never uploaded or stored on our servers.
  • Works offlineOnce the page has loaded, the tool keeps working without a connection.
InputAuto-detects Bash (Copy as cURL (bash), API docs), Windows cmd (Copy as cURL (cmd), with ^ escapes) and PowerShell (backtick line breaks). Pick one if the guess is wrong.
The most used Python HTTP library: synchronous, simple, everywhere.A requests-style API with async and HTTP/2 support. Note its 5-second default timeout and no redirects unless asked.
Adds response.raise_for_status(), so 4xx and 5xx responses raise an HTTPError instead of passing silently.
Moves the query string into a params object, which is easier to edit. Off keeps the URL exactly as pasted. Repeated keys always stay in the URL.
curl follows redirects only with -L. On: without -L the code stops at a 3xx response, exactly like curl. Off: keep the library's default.
Leaves out headers a browser adds by itself (sec-ch-ua, sec-fetch-*, priority…). They are noise when you replay a DevTools request from code.

cURL command

Paste a command from DevTools (Copy as cURL), API docs or your terminal. You can also drop a .sh or .txt file here.
Clear

Python · requests

Runnable Python that sends the same request. Lines marked in amber contain credentials.
Wrap long linesCopyDownload request.py
Your Python code appears here as you type.
Nothing leaves your browser.
Paste a command or load an example. It converts as you type, and nothing leaves your browser.

Parsed request

What curl would send, decoded: method, URL, query, headers, cookies and body.

Paste a command to see its method, URL, query parameters, headers, cookies and body, decoded.

Need this built into your own API or pipeline? Talk to our team

Quick answer

To convert cURL to Python, map the command onto the requests library: -H becomes the headers dict, the query string becomes params, -d becomes data, a JSON body becomes json, -F becomes files, -u becomes auth and -k becomes verify=False. Paste a cURL command into Playxoft's free cURL to Python converter to get runnable requests or httpx code, formatted the way Black would format it, without the command leaving your browser.

  • requests or httpx
  • Params, json, data and files
  • Cookies as a dict
  • Basic and digest auth
  • Credential warnings
  • Black-style formatting

How to use the cURL to Python Converter

  1. 1Paste a command into cURL command, or pick one from Load example.
  2. 2Choose requests or httpx as the library.
  3. 3Keep Raise on HTTP errors on to add response.raise_for_status(), and Query as params to get a params dict.
  4. 4Check Parsed request and the notes for anything Python handles differently, such as timeouts.
  5. 5Install the library with pip install requests (or pip install httpx), then copy the code or download request.py.

cURL flags cheat sheet: what does each option become in requests and httpx?

cURLrequestshttpx
-X PUTrequests.put(…)httpx.put(…)
-H "Name: value"headers={"Name": "value"}Same
?q=x in the URLparams={"q": "x"}Same
-d "a=1&b=2"data={"a": "1", "b": "2"}Same
-d with raw textdata="…"content="…"
--json '{…}' or a JSON bodyjson={…}Same
-F file=@a.pdffiles={"file": ("a.pdf", open("a.pdf", "rb"))}Same
-u user:passauth=("user", "pass")Same
--digest -u user:passauth=HTTPDigestAuth(…)auth=httpx.DigestAuth(…)
-b "a=1"cookies={"a": "1"}Same
-kverify=FalseSame
-m 30timeout=30Same
-LThe default (except for head())follow_redirects=True
-x http://host:8080proxies={"http": …, "https": …}proxy="http://host:8080"

Two details matter. json= re-serializes your data, so the spacing changes; if a server signs the exact bytes of the body, send the original string with data= instead. And requests only builds a multipart body when files= is present, so text-only -F fields become (None, value) tuples in files.

requests vs httpx: which Python library should you use?

requestshttpx
Async supportNoYes, with httpx.AsyncClient
HTTP/2NoYes, with pip install "httpx[http2]"
Default timeoutNone: it can wait forever5 seconds
RedirectsFollowed by defaultOnly with follow_redirects=True
Raw body argumentdata="…"content="…"
MaturityThe long-standing standardNewer, with a requests-style API

Use requests for scripts, notebooks and synchronous services; it is everywhere and nearly every tutorial uses it. Use httpx for asyncio code such as FastAPI handlers and async workers, or when you need HTTP/2. Whichever you choose, set a timeout: a requests call without one can hang forever on a stalled server.

Why does my Python request behave differently from curl?

The converter maps every option it can, but a few behaviors differ by design:

  • Timeouts. curl -m 30 caps the whole transfer. In requests, timeout=30 limits the connection and each read separately, so a slow trickle of data can run longer.
  • Compression. curl's --compressed needs no code: both libraries ask for gzip and decode it. The converter drops a copied Accept-Encoding header because requests can only decode Brotli (br) when the brotli package is installed.
  • Redirects. curl stops at a 3xx unless you pass -L. Turn on Match curl redirects to add allow_redirects=False and get the same response curl shows.
  • Default headers. Python sends its own User-Agent, such as python-requests/2.32. Some sites block it; keep the browser's User-Agent header from the copied command if you need to look like a browser.

How do I reuse a requests.Session for cookies and retries?

Each top-level requests.get() call builds a fresh session: no connection reuse, and cookies are forgotten. Once a converted request becomes part of a script that makes several calls, switch to a Session:

import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

session = requests.Session()
session.headers.update({"Accept": "application/json"})

retries = Retry(total=3, backoff_factor=0.5, status_forcelist=[429, 502, 503, 504])
session.mount("https://", HTTPAdapter(max_retries=retries))

response = session.get("https://api.example.com/v1/orders", timeout=30)
  • Cookies. Cookies the server sets, after a login for example, go out automatically on the next call. That replaces curl's -c and -b cookie-jar files.
  • Retries. The Retry policy is the counterpart of curl --retry. By default urllib3 only retries idempotent methods such as GET, PUT and DELETE, so a POST is not repeated unless you add it to allowed_methods.
  • httpx. The same idea is httpx.Client(); httpx.HTTPTransport(retries=3) retries failed connections.

Copying requests from a browser? See how to copy as cURL in Chrome or Firefox DevTools. Cookies arrive in a -b flag or a Cookie header, depending on the browser, and the converter turns either one into a cookies dict.

How do I keep tokens out of a Python script?

The converter itself is private: it runs in your browser and never uploads or stores your command. The risk is the token you paste, which ends up in the generated code.

Read secrets from the environment instead. Write them as variables in the command, for example -H "Authorization: Bearer $API_TOKEN", and the converter emits:

headers = {
    "Authorization": f"Bearer {os.environ['API_TOKEN']}",
}

The Contains credentials badge and the amber line markers show any secret that is still hard-coded. And when verify=False makes urllib3 print an InsecureRequestWarning on every call, take it seriously: the request now accepts forged certificates, so keep it out of production.

Frequently asked questions

Pass the data with data=. A form string like -d "a=1&b=2" becomes data={"a": "1", "b": "2"}, and requests sends it as application/x-www-form-urlencoded, just like curl. If the -d value is JSON and the command sets a JSON Content-Type, use json= instead.
data= sends a form-encoded dict, or a string or bytes exactly as given. json= serializes a Python object to JSON and sets Content-Type: application/json for you. Use json= for JSON APIs and data= when the body must match byte for byte.
Use the files argument: files={"file": ("report.pdf", open("report.pdf", "rb"), "application/pdf")}. Put plain text fields in data= alongside it. requests builds the multipart/form-data body and its boundary for you.
Pass verify=False, the equivalent of curl -k. It accepts any certificate, including forged ones, and urllib3 warns on every request. A better fix is verify="/path/to/ca.pem", pointing at the certificate authority that signed your server's certificate.
Yes. Pick httpx in the converter's library switch. The code uses the same arguments, except that raw bodies go in content= and redirects need follow_redirects=True. Remember that httpx times out after 5 seconds by default.
No. It only parses the text and generates Python code in your browser. No request is sent, nothing is uploaded, and the command disappears when you reload the page.

Last updated by the Playxoft engineering team.

From the engineers who built this tool

Fighting messy data every day?

When payloads, schemas and integrations keep breaking, the fix is usually upstream. We design typed APIs and backends that stay clean as you grow. Tell us what you are building and we will suggest the simplest architecture that fits.

More free tools

See all tools

SQL Formatter

Beautify or minify SQL in 12 dialects, with keyword case, indent and line:column errors.

Open tool

cURL to Fetch Converter

New

Turn any cURL command into JavaScript fetch() code with headers, JSON, forms and auth.

Open tool

cURL to Axios Converter

New

Convert cURL commands into an Axios request config with params, data, auth and timeouts.

Open tool

SQL to Prisma Converter

Turn SQL DDL into a schema.prisma with native types, relations and enums.

Open tool

SQL to Drizzle Converter

Turn SQL DDL into a typed Drizzle schema.ts with indexes, enums and relations().

Open tool

SVG to JSX Converter

Turn SVG markup or files into clean React and React Native components.

Open tool