curl_cffi

Enum values used by setopt and getinfo can be accessed from CurlOpt and CurlInfo.

AsyncCurl

Wrapper around curl_multi handle to provide asyncio support. It uses the libcurl socket_action APIs.

add_handle(curl, wait=True) async

Add a curl handle to be managed by curl_multi. This is the equivalent of perform in the async world.

cancel_handle(curl)

Cancel a future for given curl handle.

close()

Close and cleanup running timers, readers, writers and handles.

process_data(sockfd, ev_bitmask)

Call curl_multi_info_read to read data for given socket.

set_exception(curl, exception)

Raise exception of a future for given curl handle.

set_result(curl)

Mark a future as done for given curl handle.

setopt(option, value)

Wrapper around curl_multi_setopt.

socket_action(sockfd, ev_bitmask)

Call libcurl socket_action function

Curl

Wrapper for curl_easy_* functions of libcurl.

__init__(cacert=DEFAULT_CACERT, debug=False)

Parameters:
  • cacert (str) –

    CA cert path to use, by default, curl_cffi uses its own bundled cert.

  • debug (bool) –

    whether to show curl debug messages.

clean_after_perform(clear_headers=True)

Clean up handles and buffers after perform, called at the end of perform.

close()

Close and cleanup curl handle, wrapper for curl_easy_cleanup

get_reason_phrase(status_line)

Extract reason phrase, like OK, Not Found from response status line.

getinfo(option)

Wrapper for curl_easy_getinfo. Gets information in response after curl perform.

Parameters:
  • option (CurlInfo) –

    option to get info of, use the constants from CurlInfo enum

impersonate(target, default_headers=True)

Set the browser type to impersonate.

Parameters:
  • target (str) –

    browser to impersonate.

  • default_headers (bool) –

    whether to add default headers, like User-Agent.

Extract cookies.SimpleCookie from header lines.

Parameters:
  • headers (List[bytes]) –

    list of headers in bytes.

Returns:
  • SimpleCookie

    A parsed cookies.SimpleCookie instance.

perform(clear_headers=True)

Wrapper for curl_easy_perform, performs a curl request.

Parameters:
  • clear_headers (bool) –

    clear header slist used in this perform

reset()

Reset all curl options, wrapper for curl_easy_reset.

setopt(option, value)

Wrapper for curl_easy_setopt.

Parameters:
  • option (CurlOpt) –

    option to set, use the constants from CurlOpt enum

  • value (Any) –

    value to set, strings will be handled automatically

version()

Get the underlying libcurl version.

CurlError

Bases: Exception

Base exception for curl_cffi package