uncurl for httpx, fork from uncurl-requests
Project description
Forked from https://github.com/spulec/uncurl
Changes In This Fork
- Switched generated client code from
requeststohttpx. - Updated proxy and redirect argument rendering to match
httpxsemantics. - Removed Python 2 compatibility code and standardized on Python 3.
- Replaced legacy test tooling with
pytestand simplified the test suite. - Removed unused legacy dependencies such as
six,mock,sure,nose, andcoverage. - Improved code generation safety by using Python-safe literals instead of manual string quoting.
- Unified cookie parsing so
--cookieandCookie:headers are handled consistently. - Omit empty request arguments in generated output to produce cleaner
httpxcode.
Uncurl - Converting curl requests to httpx
In a nutshell
Uncurl is a library that allows you to convert curl requests into python code that uses httpx. Since the Chrome network inspector has a nifty "Copy as cURL", this tool is useful for recreating browser requests in python.
When you don't pass any arguments to uncurl, it will use whatever is in your clipboard as the curl command.
Example
$ uncurl "curl 'https://pypi.python.org/pypi/uncurl-httpx' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Cookie: foo=bar;' -H 'Connection: keep-alive' --compressed"
httpx.get("https://pypi.python.org/pypi/uncurl-httpx", headers={
"Accept-Encoding": "gzip,deflate,sdch",
"Accept-Language": "en-US,en;q=0.8",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
}, cookies={
"foo": "bar",
})
The underlying API:
import uncurl
print(uncurl.parse("curl 'https://pypi.python.org/pypi/uncurl-httpx' -H 'Accept-Encoding: gzip,deflate,sdch'"))
如果你想直接发起请求,也可以调用:
import uncurl
response = uncurl.request(
"curl 'https://pypi.python.org/pypi/uncurl-httpx' -H 'Accept-Encoding: gzip,deflate,sdch'",
timeout=5.0,
)
print(response.status_code)
prints the string
'httpx.get("https://pypi.python.org/pypi/uncurl-httpx", headers={
"Accept-Encoding": "gzip,deflate,sdch",
})'
You can also retrieve the components as python objects:
>>> import uncurl
>>> context = uncurl.parse_context("curl 'https://pypi.python.org/pypi/uncurl-httpx' -H 'Accept-Encoding: gzip,deflate,sdch'")
>>> context.url
https://pypi.python.org/pypi/uncurl-httpx
>>> context.headers
OrderedDict([('Accept-Encoding', 'gzip,deflate,sdch')])
On Mac OS, you can also pipe input to uncurl:
pbpaste | uncurl
Install
$ pip install uncurl
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uncurl_httpx-0.1.0.tar.gz.
File metadata
- Download URL: uncurl_httpx-0.1.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b2805694aaf6f24e9db22e1c0b8e67a734ff110a341d36290c44a2fe340c9d7
|
|
| MD5 |
f354de373a71978a6740cf298f48bd58
|
|
| BLAKE2b-256 |
bae4a5968de4cfe2e5415eff6592e53d9535eee71c82357206eb3284ef6fc122
|
File details
Details for the file uncurl_httpx-0.1.0-py3-none-any.whl.
File metadata
- Download URL: uncurl_httpx-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2e9709766d5e8663b1da3c9662edab1369db084ca6ab70c669272a07014f97f
|
|
| MD5 |
c3f5a7047016a8bb3f84ea28a9877704
|
|
| BLAKE2b-256 |
66702580da94dd89b0cf140ebeaeed0b50f18f53d814a378c026e4f48a353fee
|