Skip to main content

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 --cookie is 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


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.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

curl_session-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file curl_session-0.1.0.tar.gz.

File metadata

  • Download URL: curl_session-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for curl_session-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d4ae3472b67fbe2b1090e6141b9e24c1910eb01c740143ba89921d6031b4d5bd
MD5 e45b6888dbe54e4d57fcba228a71e28d
BLAKE2b-256 cad69d7c7b0c56de113fe40e43a02320c37a85f9829a4bdd6ea79f7811f44258

See more details on using hashes here.

File details

Details for the file curl_session-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: curl_session-0.1.0-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

Hashes for curl_session-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f63751a7a068c4b0b08a959f95b7f79a730f9a066e9d0636a2aa988948c940a3
MD5 c2f9ebfd2b0a00e5b89e2563c9df74c1
BLAKE2b-256 d3303500b833f2fcd7e8d01d570859998e5dfeb4cae08cd89f639f4636f99f5d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page