Skip to content
TabBench

cURL to Python Converter

Paste a curl command and get Python code using requests, httpx or the standard-library urllib, with headers, JSON or form data, auth, files and timeouts.

Runs in your browser. Nothing you add is uploaded.

What the cURL to Python Converter does

Converting a curl command to Python is mostly bookkeeping: headers become a dictionary, -d becomes json= or data=, -u becomes an auth tuple, -F becomes files=, -m becomes a timeout. This converter does it for you in three flavours. requests is the everyday choice, httpx adds async and HTTP/2, and urllib ships with Python for when nothing else can be installed. It also explains the differences that catch people out, such as requests following redirects by default.

How to convert curl to Python

  1. Paste the curl command.
  2. Pick the library: requests, httpx or urllib.
  3. Keep “Check for errors” on if you want response.raise_for_status() after the call.
  4. Turn on “Match curl's redirect behaviour” if you want redirects ignored as curl does without -L.
  5. Copy the code, install the package (pip install requests) if needed, and replace placeholders.

The cURL to Python Converter runs entirely in your browser — nothing you enter is uploaded, stored, or logged.

When to use it

Scripting an API from its docs

Paste the curl example from a provider and get a runnable Python script for cron jobs, data pipelines and notebooks.

Replaying a browser request

Use Copy as cURL in DevTools, convert it and reproduce the call from Python to scrape or test an endpoint you are allowed to use.

Moving off a fragile shell script

Replace a bash script that builds curl commands with Python that can parse JSON and handle errors.

Good to know

  • requests has no default timeout, so a stuck connection can hang forever. Always pass timeout=.
  • Use json= instead of data= for JSON bodies: it serialises the dict and sets Content-Type.
  • requests follows redirects by default for GET but not for HEAD.
  • httpx times out after five seconds unless you set timeout.
  • For many requests, create a Session (requests) or Client (httpx) so connections are reused.

Guides that use this tool

Frequently asked questions

Which library should I choose?

requests is the most widely used and is fine for most scripts. httpx adds async support and HTTP/2. urllib needs no installation but is more verbose and has no multipart helper.

Why does the code send my JSON with json= instead of data=?

json= serialises the dict and sets the Content-Type header for you, which is what curl -H 'Content-Type: application/json' -d '{…}' does by hand. Bodies that are not valid JSON are sent as a string with data=.

Does the converter run my request?

No. It only reads the command and writes code. Nothing is sent anywhere, and the curl text stays in your browser.

How do I send a file upload from Python?

Pass files={'file': open('photo.jpg', 'rb')} to requests.post. The converter builds it from -F, including the file name and content type, and uses data= for ordinary fields in the same form.

What does verify=False do?

It turns off TLS certificate verification, like curl -k. Use it only for local testing, because it removes the protection HTTPS gives and Python will print warnings.

Why does the urllib output raise an exception on a 404?

urllib raises urllib.error.HTTPError for 4xx and 5xx responses. requests does not until you call raise_for_status().