Initialize from a curl command string and get equivalent requests.Session and httpx.Client objects
Project description
CurlSession
pip install curl-session
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)
MultiCurl Usage
Use MultiCurl to parse and execute multiple cURL commands from a string, with optional filtering and delays.
from curl_session import multi_curl
curl_commands = """
curl 'https://example.com/api1'
curl 'https://example.com/api2' -H 'Authorization: Bearer token'
"""
mc = multi_curl.MultiCurl(curl_commands)
results = mc.run(delay=1.0, url_filter='api1') # Run with 1s delay, filter by URL substring
for curl in results:
print(f"URL: {curl.url}, Status: {curl.status_code}, Response: {curl.response}")
Tests
- Install deps
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pytest -q
Build and Deploy to PyPI
run release.sh
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
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.11.tar.gz.
File metadata
- Download URL: curl_session-0.1.11.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5da319ed1cb3701b166a9fa209a84eb61267dfda9e6d7540083ce9fa3aa63221
|
|
| MD5 |
983815c91e794c4de67f0c3f5a14a474
|
|
| BLAKE2b-256 |
b4e4741957d12adc02570cb77c396908bf0f8c4f3e2b95a4461c4224e20e8761
|
File details
Details for the file curl_session-0.1.11-py3-none-any.whl.
File metadata
- Download URL: curl_session-0.1.11-py3-none-any.whl
- Upload date:
- Size: 10.8 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 |
688455457adda9280ce413169d3fcd289755a0dc82c442427e30ab2796e5c6cd
|
|
| MD5 |
7b8afe443cb46f5c50a78b072a0729dc
|
|
| BLAKE2b-256 |
4f6d7b536cce454778686bf16b4cf4a15943e9e247b4cde6b0a0389d57003fd6
|