Initialize from a curl command string and get equivalent requests.Session and httpx.Client objects
Project description
CurlSession
Initialize from a curl command string and get equivalent requests.Session and httpx.Client objects with the same headers, cookies, proxies, TLS options, and redirect/http2 behavior.
Usage
from curl_session import CurlSession
curl = 'curl -H "Accept: application/json" -b "a=1; b=2" https://example.com/api'
cs = CurlSession(curl)
# httpx
with cs.get_httpx_client() as client:
r = client.get(cs._parsed.url) # provide a URL as in original curl if needed
print(r.text)
# requests
with cs.get_requests_session() as s:
r = s.get(cs._parsed.url)
print(r.text)
# run original curl
cp = cs.run()
print(cp.stdout)
Tests
- Install deps
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pytest -q
Notes
- This is a pragmatic parser covering common curl flags for headers, cookies, data, proxies, TLS, auth, redirect, and http2 options.
- If
--cookieis a filename, it's ignored for safety. Provide explicit cookie strings instead. - Timeouts and other runtime-only flags are intentionally not persisted to the session defaults.
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
curl_session-0.1.1.tar.gz
(6.6 kB
view details)
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 curl_session-0.1.1.tar.gz.
File metadata
- Download URL: curl_session-0.1.1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d20f676e6a89ba3e3a7f9311b6819abf1dd3d670cf06169aa8bc812009fafd8
|
|
| MD5 |
9002a49e15f0a02c82fd36fbee33400c
|
|
| BLAKE2b-256 |
62927a36f7df2e3832842c17cee142e8b1d2feb1c1d1e7d7dff20fdfc9cc42a4
|
File details
Details for the file curl_session-0.1.1-py3-none-any.whl.
File metadata
- Download URL: curl_session-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36fb11e52b1df908fb55723aa69d6e9eddbf6440f2a8b1ca3c4d421f59cb6e37
|
|
| MD5 |
b8fb73b74dcd58ac004dd1b6feea6767
|
|
| BLAKE2b-256 |
c87218e06ff69c5d9e4cc723981687fa8ba010386c2c8afb51740fce570f7432
|