{"id":8750,"library":"uncurl","title":"uncurl - Convert curl to python-requests","description":"uncurl is a Python library that translates `curl` command-line requests into equivalent Python `requests` library code. It's particularly useful for converting `curl` commands copied from browser developer tools into runnable Python scripts. The current version is 0.0.11, and its release cadence is slow, with the last update in March 2021.","status":"maintenance","version":"0.0.11","language":"en","source_language":"en","source_url":"https://github.com/spulec/uncurl","tags":["curl","requests","http","api","cli","utility"],"install":[{"cmd":"pip install uncurl","lang":"bash","label":"Install `uncurl`"}],"dependencies":[{"reason":"Required to execute the Python code generated by uncurl, though not a direct runtime dependency of the uncurl library itself.","package":"requests","optional":false},{"reason":"Needed for clipboard integration when using the command-line tool without explicit input, especially on non-macOS systems.","package":"pyperclip","optional":true}],"imports":[{"note":"The `parse` function is directly imported from the `uncurl` package.","wrong":"import uncurl.parse","symbol":"parse","correct":"from uncurl import parse"},{"note":"The `parse_context` function is directly imported and provides structured data.","wrong":"import uncurl.parse_context","symbol":"parse_context","correct":"from uncurl import parse_context"}],"quickstart":{"code":"import uncurl\nimport requests\n\ncurl_command = \"curl 'https://pypi.python.org/pypi/uncurl' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'User-Agent: Mozilla/5.0' --compressed\"\n\n# Get structured components of the curl command\ncontext = uncurl.parse_context(curl_command)\n\n# Construct and execute the requests call\nresponse = requests.request(\n    context.method.upper(),\n    context.url,\n    headers=context.headers,\n    data=context.data,\n    cookies=context.cookies,\n    auth=context.auth,\n    verify=(not context.insecure) # handle --insecure curl flag\n)\n\nprint(f\"Status Code: {response.status_code}\")\n# print(response.text)\n\n# Alternatively, get the requests code as a string\n# requests_code_string = uncurl.parse(curl_command)\n# print(requests_code_string)","lang":"python","description":"This quickstart demonstrates how to use `uncurl.parse_context` to extract components from a `curl` command and then build and execute a `requests` call. This method is generally more robust than `uncurl.parse` for complex commands. It also shows how to get the `requests` code as a string directly."},"warnings":[{"fix":"For cutting-edge `curl` features or complex, evolving web environments, consider manually verifying `uncurl`'s output or exploring alternatives/forks like `uncurlx` for `httpx`.","message":"The `uncurl` library's last release was in March 2021. This suggests a low level of active maintenance, which might affect its compatibility with very recent `curl` versions or advanced, newer `curl` features and syntax.","severity":"gotcha","affected_versions":"<=0.0.11"},{"fix":"Always inspect the output of `uncurl.parse_context()` and the resulting `requests` call. Manual adjustments to headers, data, or the `auth` parameter may be necessary. For problematic `curl` options like `-u` or `-X`, consider stripping them or handling them explicitly after parsing.","message":"Complex `curl` commands, especially those with intricate authentication mechanisms (e.g., NTLM, Kerberos), multi-part form data, or highly specific header encoding, might not be fully or accurately translated by `uncurl`.","severity":"gotcha","affected_versions":"<=0.0.11"},{"fix":"On Linux, use `xclip -o | uncurl` (with `xclip` installed) or manually paste the `curl` command string as an argument. For cross-platform clipboard support, install `pip install pyperclip` and integrate it into your script.","message":"The `uncurl` command-line tool's clipboard integration (e.g., `pbpaste | uncurl`) is primarily demonstrated and might work best for macOS. On other operating systems, you may need to manually pipe the `curl` command to `uncurl` or install the `pyperclip` library for seamless clipboard access.","severity":"gotcha","affected_versions":"<=0.0.11"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Instead of `uncurl.parse()`, use `uncurl.parse_context()` which returns a structured object containing URL, headers, method, data, cookies, and authentication. You can then use these components to build a `requests` call more reliably. Alternatively, simplify the `curl` command before passing it to `uncurl.parse()`.","cause":"The `uncurl.parse()` function can be less robust with certain `curl` command-line options when trying to directly generate a `requests` string, leading to incomplete or incorrect output.","error":"Curl command options like -u , -X etc are rejected."},{"fix":"You need to explicitly install the `requests` library in your environment: `pip install requests`.","cause":"`uncurl` converts `curl` commands into Python code that typically uses the `requests` library. However, `requests` is not a direct runtime dependency of `uncurl` itself and is not automatically installed when you install `uncurl`.","error":"ModuleNotFoundError: No module named 'requests'"},{"fix":"Examine the original `curl` command closely. Use `uncurl.parse_context()` to get detailed components and then debug the `requests` call by inspecting `context.headers`, `context.data`, `context.cookies`, `context.auth`, and the `verify` parameter. Ensure `requests` is handling compression (often automatic) and certificate validation as intended.","cause":"The translation from a `curl` command to `requests` code might not always be perfect, especially for non-standard headers, complex POST data, or specific `curl` flags (like `--compressed` which `requests` handles automatically, or certificate validation with `-k`/`--insecure`).","error":"uncurl generated requests code not working as expected"}]}