Home Tools Blog About

Convert Curl to Python Requests

In short

Convert cURL to Python requests/httpx/aiohttp. JSON-safe, auth, cookies, multipart. Free, offline, client-side, instant, secure.

  • Runs in your browser
  • Nothing uploaded
  • Free, no sign-up

Convert cURL commands to Python requests, httpx, or aiohttp code. Backslash escapes inside single-quoted bodies are handled correctly.

🛡
100% PrivateNo server uploads, ever
InstantRuns in your browser
💧
No WatermarksClean output, always
🆓
Free ForeverNo accounts, no limits

How to Use Convert Curl to Python Requests

  1. In Chrome/Edge DevTools → Network tab → right-click any request → Copy → Copy as cURL (bash). On Firefox use the same menu without the bash suffix.
  2. Paste into the left pane. Or click Load sample to see expected formats.
  3. Pick a target library: requests (sync, default), httpx (sync, modern), or aiohttp (async - wraps in async def main() + asyncio.run()).
  4. For requests target, tick Session wrapper if you'll reuse connection/auth across many requests in the same script.
  5. Press Ctrl+Enter to convert (or just wait - live preview after 250 ms idle).
  6. Copy or download request.py.

Frequently Asked Questions

requests vs httpx vs aiohttp – which?

requests: simplest API, sync only, dependency you already have. Use for scripts and most code. httpx: similar API to requests but with HTTP/2, sync + async support, type hints. Drop-in upgrade if you want HTTP/2. aiohttp: async only, requires asyncio. Use when concurrent requests matter (scraping, fanout to many APIs). The aiohttp output wraps your call in async def main() + asyncio.run(main()) boilerplate.

What about JSON bodies – does it use json= or data=?

When the body parses as JSON, the tool emits a Python literal dict/list (not a string) and passes it as json=data. requests/httpx/aiohttp all auto-set Content-Type: application/json and serialize. If you had an explicit Content-Type header in your cURL, it’s preserved – the library generally honors the explicit one. For non-JSON bodies (form-encoded, plain text), uses data= with the body as a Python double-quoted string.

How does basic auth (-u) work?

cURL: -u admin:secret becomes auth=('admin', 'secret') on requests/httpx (built-in tuple form). On aiohttp: auth=aiohttp.BasicAuth('admin', 'secret'). The password preserves colons: -u 'user:pa:ss'('user', 'pa:ss') (split on first colon only).

How is multipart (-F) converted?

cURL: -F '[email protected]'files={'file': ('photo.jpg', open('photo.jpg', 'rb'))} with a comment that the path is relative to Python cwd at runtime. Non-file fields (-F 'caption=hello') go into a separate form_data dict passed as data=form_data. Don’t forget to close() the file handle or use a with block in production code (the tool emits the minimal version for brevity).

What about -G + -d?

cURL: curl -G 'https://api.com/search' -d 'q=hi' -d 'lim=10' → emits params={'q': 'hi', 'lim': '10'} and passes as params=params to requests.get(). No body. Method stays GET. The -d values are URL-decoded for the dict (so -d 'q=hello%20world' becomes 'q': 'hello world').

Does it handle multi-line cURL with \ continuation?

Yes. Backslash-newline (and backslash-CR-LF on Windows) is collapsed to a single space before tokenisation. So curl 'https://x.com' \
-H 'A: b' \
-d 'data'
works as expected.

Why use POSIX-correct tokenization for single quotes?

In POSIX shell (bash, sh, zsh), single-quoted strings are 100% literal – no backslash escapes, no variable expansion. Double-quoted strings honor \", \\, \$, \`. Chrome DevTools “Copy as cURL” uses single quotes for everything, so this bug hit every real-world command with backslashes (regex patterns, Windows paths, etc.).

What’s not supported?

Not converted: --cert, --key, --cacert (requests’ cert= takes a path or tuple – add manually with the file path), --proxy (would become proxies={'http': '...', 'https': '...'} – easy to add manually), -o/--output (use with open('file', 'wb') as f: f.write(response.content)), --resolve (DNS override), HTTP/2-specific flags. NTLM/Digest auth not handled (would need requests-ntlm package).

Is my data secure?

Yes. cURL input + generated Python stay in your browser. No network requests are made and no data is logged. Bearer tokens, basic auth credentials, and cookies in your cURL never leave your device.

Keep going

Related Tools

All Developer tools →

Convert Curl to Fetch

Convert cURL to fetch/axios/node-fetch with TypeScript option. Handles auth, cookies, JSON body without double-encoding.…

Convert Curl to Php Curl

Convert cURL to PHP curl_setopt() code. Auto-POST detection, JSON-safe parsing, basic auth, cookies, multipart.…

Android AssetLinks JSON Generator - App Links

Android AssetLinks JSON Generator files for Android App Links. Configure package names and SHA-256…

Convert ASCII to Binary

Convert ASCII to Binary tool. Convert text to binary and binary to text. 100%…

Base32 Encoder/Decoder

Free Base32 encoder and decoder tool. Encode or decode Base32 strings online. 100% client-side,…

Base58 Encoder/Decoder

Free Base58 encoder and decoder tool. Encode or decode Base58 strings like Bitcoin addresses.…

Base64 Encoder and Decoder

Base64 Encoder and Decoder - Convert text strings into Base64 format or decode Base64…

BBCode to HTML Converter

Generate standard semantic HTML arrays translating classic forum BBCode syntax cleanly explicitly mappings independently…

Convert Binary to Hex

Convert Binary to Hex tool. Convert binary numbers to hex instantly. 100% client-side, instant,…

Convert BSON to JSON

Convert MongoDB BSON hex dumps to readable JSON in your browser. Free, offline, client-side…

Chmod Calculator

Chmod Calculator - Build Linux chmod permissions visually - read/write/execute for owner, group, public,…

Coin Flip

Free Coin Flip Online streaks, batch 10 000 flips, and optional crypto-grade RNG. Full…

Share

Embed this tool

Add this free tool to your website. Copy and paste the code: