cURL to Python — Convert cURL Commands to Python Code
Convert cURL commands to Python `requests` or `httpx` code. Auth, cookies, and bodies handled, runs entirely in your browser. No uploads, no limits.
cURL to Python
Convert cURL commands to Python requests code. Works entirely in your browser — no uploads.
cURL to Python is the most-used cURL-to-language conversion in any developer’s toolbox, because Python’s requests library is the shortest, most readable way to make an HTTP call in any language, and the conversion from cURL to requests is mechanical. Headers become a headers dict. The body becomes a data= or json= argument. Authentication becomes an auth= tuple or a Bearer header. Cookies become a cookies= dict. The output is a 5-line snippet that does what a 30-line Bash cURL invocation does, but with the kind of error handling and parameterization that makes it usable in a real Python service.
The non-obvious thing about cURL-to-Python is the library choice. The default requests is the right pick for 90 percent of use cases — synchronous, well-known, and the de facto standard for Python HTTP. httpx is the right pick for async code (FastAPI services, asyncio scripts) and for HTTP/2 support. urllib is the right pick for stdlib-only environments where installing third-party packages is not an option. The tool’s library toggle switches the output: the request shape is the same, the import line and the function call adapt. For most users, requests is the right default; the toggle exists for the cases where it is not.
For a final hand-off: if the goal is a script, paste the output into a .py file and add if __name__ == \"__main__\": boilerplate. If the goal is a service, wrap the call in a function with proper error handling and a timeout. If the goal is an async codebase, pick httpx and toggle the async option. If the goal is one-off debugging, the output as-is is enough — paste it into a Python REPL or a Jupyter cell and run it.
How to use
Paste a cURL command
Copy a cURL command from browser DevTools (Network tab > Copy as cURL), a documentation page, or your shell history. The parser handles `-H`, `-d`, `-X`, `-u`, `--cookie`, `--data-binary`, and other common flags.
Pick a Python HTTP library
Choose `requests` (the most popular, synchronous, simple), `httpx` (modern, async-capable, requests-compatible API), or `urllib` (stdlib, no dependencies). The output adapts the import line, the function call, and the response handling.
Customize the output
The default output is a single function call. Toggle options to add timeout handling, retry logic, JSON response parsing, or to wrap the call in a `with` block for the `httpx` client variant.
Frequently asked
Should I pick requests or httpx?
Requests is the right pick for scripts, simple services, and anywhere async is not needed. httpx is the right pick for async code (FastAPI, asyncio scripts) and for code that needs HTTP/2 support. The APIs are nearly identical; switching is a 5-line change.
Does it work with Python 2?
The default output targets Python 3.6+ (f-strings, type hints, modern syntax). For Python 2.7 compatibility, manually adapt the f-strings to `.format()` calls. The `requests` library itself supports both versions, but f-strings do not.
How are cookies and authentication handled?
`-b 'name=value'` becomes a `cookies=` dict or a `Cookie` header. `-u 'user:pass'` becomes a `requests.auth.HTTPBasicAuth` object passed to the `auth` parameter. Bearer tokens from `-H 'Authorization: Bearer ...'` are preserved as a raw header.
Can I generate async code?
Yes — pick `httpx` and toggle the 'async' option. The output uses `httpx.AsyncClient()` with `async def` and `await`. The request shape matches the synchronous version, so the conversion is one line of code in the generated snippet.
What about file uploads and multipart forms?
Multipart form uploads (`-F file=@path`) are supported. The output uses `files={'file': open('path', 'rb')}` for `requests` and the equivalent for `httpx`. For binary uploads, the tool also handles `--data-binary @file` with a `data=open(...)` argument.
Limitations
- No retry logic by defaultThe generated code makes a single request and returns the response. For production use, add `requests.adapters.HTTPAdapter` with a retry policy, or use the `tenacity` library for exponential backoff on transient errors.
- No session reuseThe default output creates a new client per call. For multiple requests to the same host, wrap the calls in a `with requests.Session() as s:` block. The tool does not auto-add the session because some users want standalone calls.
- No streaming responsesThe default output reads the entire response body into memory. For streaming downloads, use `response.iter_content()` (requests) or `response.aiter_bytes()` (httpx). The tool emits the non-streaming version as the standard pattern.
Platform notes
- macOS
- Python 3.6+ is required for the f-string syntax in the output. The `requests` and `httpx` libraries install via `pip install requests httpx`. Both ship wheels for macOS, so no compiler is needed.
- Windows
- Python 3.6+ is required. Install via the official .exe from python.org or through the Microsoft Store. The `requests` and `httpx` libraries install via `pip install` without platform-specific build steps.
- Linux
- Python 3.6+ is required. Most distros ship Python 3.6+ in their default repos. The `requests` and `httpx` libraries install via `pip install` and have no system-level dependencies for the wheel builds.
- CLI
- The same library that powers this tool is available as the `curlconverter` package on npm, with a `curlconverter --language python` CLI mode. Useful for embedding in build scripts or for batch conversion of saved cURL commands.
- Web
- Runs entirely client-side. Works offline once the page has loaded. The generated Python is portable — paste it into any Python script, a Jupyter notebook, or a FastAPI endpoint without dependencies.