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.
pip install uncurlVerified import paths — ran on the pinned version, not inferred.
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.
For cutting-edge `curl` features or complex, evolving web environments, consider manually verifying `uncurl`'s output or exploring alternatives/forks like `uncurlx` for `httpx`.
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.
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.
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()`.
You need to explicitly install the `requests` library in your environment: `pip install requests`.
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.