Registry / http-networking / uncurl

uncurl

JSON →
library0.0.11pypypi✓ verified 90d ago

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 uncurl
INSTALL
IMPORT
SIG · UNCURL
U
uncurl
http-networkingpythonv0.0.11
Install
1.6s avg
Import
42ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.0.11 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.045s · 18MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.040s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
✓ from uncurl import parse
✗ import uncurl.parse
The `parse` function is directly imported from the `uncurl` package.
parse_context
✓ from uncurl import parse_context
✗ import uncurl.parse_context
The `parse_context` function is directly imported and provides structured data.

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.

import uncurl import requests curl_command = "curl 'https://pypi.python.org/pypi/uncurl' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'User-Agent: Mozilla/5.0' --compressed" # Get structured components of the curl command context = uncurl.parse_context(curl_command) # Construct and execute the requests call response = requests.request( context.method.upper(), context.url, headers=context.headers, data=context.data, cookies=context.cookies, auth=context.auth, verify=(not context.insecure) # handle --insecure curl flag ) print(f"Status Code: {response.status_code}") # print(response.text) # Alternatively, get the requests code as a string # requests_code_string = uncurl.parse(curl_command) # print(requests_code_string)
Debug
Known issues
gotchaThe `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.
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`.
affects: <=0.0.11
gotchaComplex `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`.
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.
affects: <=0.0.11
gotchaThe `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.
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.
affects: <=0.0.11
Errors
Common errors & fixes
Curl command options like -u , -X etc are rejected.
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.
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()`.
ModuleNotFoundError: No module named 'requests'
`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`.
fix
You need to explicitly install the `requests` library in your environment: `pip install requests`.
uncurl generated requests code not working as expected
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`).
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.
Upgrade
Version history
0.0.11latest on PyPI · released Mar 21, 2021
Audit
Dependencies
requestsrequiredRequired to execute the Python code generated by uncurl, though not a direct runtime dependency of the uncurl library itself.
pyperclipoptionalNeeded for clipboard integration when using the command-line tool without explicit input, especially on non-macOS systems.
Agent activity
21 hits · last 30 days
node
20
OpenAI (training)
1
Resources
uncurl — pip install uncurl · libregistry