Loading...
Loading...
Paste a curl command and get clean Python code. Supports requests, httpx, aiohttp, and urllib3. Auto-detects JSON bodies and optimizes headers.
import requests url = "https://api.openai.com/v1/chat/completions" headers = {"Authorization": "Bearer sk-your-key-here"} json_data = { "model": "gpt-4", "messages": [ { "role": "user", "content": "Hello", }, ], } response = requests.post(url, headers=headers, json=json_data) print(response.status_code) print(response.json())
Paste your curl command into the converter above and select the "requests" tab. The tool parses all flags (-X, -H, -d, -u, -F, etc.) and generates clean Python code with proper json= parameter usage, auth handling, and header optimization.
For most use cases, the requests library is the standard choice - simple API, great documentation, and widespread community support. Use httpx if you need async support or HTTP/2. Use aiohttp for high-concurrency async applications. Use urllib3 for low-level control or when you need connection pooling without the requests overhead.
Use the json= parameter instead of data=. For example: requests.post(url, json={"key": "value"}). This automatically sets the Content-Type header to application/json and serializes your dictionary. The converter detects JSON bodies in curl commands and uses json= automatically.
For Basic auth, use the auth= parameter: requests.get(url, auth=("user", "pass")). For Bearer tokens, add an Authorization header: headers={"Authorization": "Bearer your-token"}. The converter handles both -u (Basic auth) and -H "Authorization: Bearer ..." (Bearer token) from curl.
httpx is a modern HTTP client that supports both sync and async operations, HTTP/2, and has a nearly identical API to requests. Choose httpx when you need async/await support, HTTP/2, or a more modern client. Choose requests for maximum compatibility and simplicity.