Dev Converters
HTTP

cURL to Python requests Converter

Convert cURL commands to Python using the requests library. Generates idiomatic code with headers dict, json= or data= body, and timeout.

How it works

The Python `requests` library is the de facto standard for HTTP in Python — readable, forgiving, and widely documented. Translating a curl command into `requests` is a common first step when turning an ad-hoc API call into a script or a scheduled job.

This converter parses the curl command, categorises the body (JSON vs form-encoded vs raw), and emits idiomatic Python. JSON bodies use `json=` (so requests sets `Content-Type: application/json` automatically and serialises the dict). Form bodies use `data=` with a dict. Raw bodies become a string passed to `data=`. Headers are rendered as a Python dict literal with trailing commas for clean diffs.

A couple of sensible defaults are baked in: every request gets `timeout=30` because blocking forever on a bad network is a common bug, and the snippet prints `response.status_code` and `response.text` so you see immediate feedback when running the script. If you need to reuse cookies across requests, wrap the call in `with requests.Session() as s:` and use `s.post` etc. Basic-auth `-u` is translated to the `auth=` tuple argument.

Frequently asked questions

Why use json= instead of data= for JSON bodies?
Passing json= tells requests to serialise the dict and set Content-Type automatically. It also handles type coercion cleanly.
Is the timeout mandatory?
Not in requests itself, but omitting a timeout is a common source of hung processes in production. The generator adds timeout=30 by default.
What about session cookies?
A single --cookie flag becomes a Cookie header. For multi-request sessions, wrap the call in requests.Session() manually.

Related tools