Convert curl to Python
curl2code instantly converts any curl command into clean Python code using the popular requests library. The conversion runs entirely in your browser via WebAssembly — your data never leaves your device. If you work with TypeScript on the frontend, check out our curl to TypeScript converter. For server-side JavaScript, see curl to Node.js. Below you'll find practical examples covering the most common HTTP scenarios.
How to copy curl from your browser
- 1
Open DevTools
Press F12 or Ctrl+Shift+I to open your browser developer tools.
- 2
Go to the Network tab
Click the Network tab and perform the action that triggers the HTTP request.
- 3
Copy as cURL
Right-click the request → Copy → Copy as cURL. Then paste it above.
Frequently Asked Questions
What is Python Requests?
Python Requests is the most popular HTTP client library for Python with over 50,000 GitHub stars. It provides an elegant, Pythonic API for making HTTP requests, handling sessions, cookies, and authentication. It supports JSON parsing out of the box, connection pooling, and automatic content decoding. Install it with pip install requests. It's the default library used by curl2code for Python conversions.
Requests vs http.client — which should I use?
Requests is recommended for most use cases due to its simple API, automatic JSON parsing, and built-in session support. http.client is part of the Python standard library and requires no installation, making it suitable for minimal environments. For similar simplicity in other languages, see our curl to Ruby converter or curl to Go converter.
How to handle authentication in Python Requests?
Pass an Authorization header with your token for Bearer auth, or use requests.auth.HTTPBasicAuth(user, pass) for Basic auth. curl2code automatically detects auth patterns including -u user:pass and -H 'Authorization: Bearer ...'.
How to send multipart form data with Python?
Use the files parameter: requests.post(url, files={ 'file': open('doc.pdf', 'rb') }). For additional form fields, use data simultaneously. curl2code handles -F flags automatically.
How to handle errors and retries?
Use response.raise_for_status() for exceptions on 4xx/5xx. Wrap in try/except catching requests.exceptions.RequestException. For retries, use urllib3.util.Retry with a Session adapter.
How to make async HTTP requests in Python?
requests is synchronous. For async HTTP, use aiohttp or httpx (offers both sync and async APIs with requests-compatible interface). For high-concurrency scenarios, async clients provide significantly better throughput.
How to set timeouts and connection pooling?
Always set timeouts: requests.get(url, timeout=(3.05, 27)). For connection pooling, use requests.Session() which reuses TCP connections. curl's --connect-timeout and --max-time map to these.
How to configure a proxy with Python Requests?
Pass a proxies dict: { 'https': 'http://proxy:8080' }. For SOCKS, install requests[socks]. Also respects HTTP_PROXY / HTTPS_PROXY env vars. curl2code converts -x and --proxy automatically.
How to send a POST request with JSON body in Python?
Convert a curl POST command like curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' URL to Python using curl2code. The generated code uses requests.post(url, json={'key': 'value'}). curl2code automatically detects -d/--data flags with JSON content and sets the appropriate Content-Type header in the Requests code.
How to add Bearer token authorization in Python?
Pass curl -H "Authorization: Bearer YOUR_TOKEN" URL to curl2code and it generates Requests code with the auth header: headers={'Authorization': 'Bearer YOUR_TOKEN'}. curl2code detects Bearer tokens from both -H "Authorization: Bearer ..." and --oauth2-bearer flags. For Basic auth, use -u user:pass.
How to set Content-Type header in Python?
curl2code converts curl -H "Content-Type: application/json" URL to Requests code with the proper header: headers={'Content-Type': 'application/json'}. For -d data, curl defaults to application/x-www-form-urlencoded; for -F form uploads, it uses multipart/form-data. curl2code maps each to the correct Requests API.
How to convert a curl command to Python code?
Paste your curl command into curl2code and select Python. The tool parses all flags — -X (method), -H (headers), -d (data), -u (auth), -F (form), cookies, and more — and generates clean Python Requests code. The conversion runs locally in your browser via WebAssembly, so your API keys and data stay private. You can also choose http.client as an alternative library.