Konnect Curl Core (konnect.curl)

gitlab-ico

licence-mpl20 pre-commit-ico

Konnect

Konnect is a project to make the power of the libcurl multi feature available through a Pythonic interface. It consists of this core package (konnect.curl) through which any protocol provided by libcurl can be accessed and some additional packages (e.g. konnect.http) which provide enhanced interfaces for specific protocols.

Basic Usage

Users must first create a class that implements the RequestProtocol interface; the methods of this protocol are essentially hooks that are called at certain points in a transfer. The transfer commences when an instance of the request class is passed to Multi.process() and the returned awaitable is awaited:

  • configure_handle is called prior to connection with a single ConfigHandle object as an argument. This object can be used to configure the request in a manner familiar to users of libcurl, by calling the ConfigHandle.setopt() method of the object. In particular users should configure libcurl callbacks to handle various additional events specific to the desired protocol.

  • has_update & get_update are called continuously throughout the transfer. The latter, if it returns anything, interrupts the transfer and returns the value from Multi.process(). The user would normally then continue the transfer by calling Multi.process() again with the same multi and request objects. It is up to the user to recognise when the return is an interim response or a final response, normally by checking the type of the response. If the implementation has nothing to return during the transfer has_update can simply return False every time it is called.

  • completed is called after the transfer is finished, with a GetInfoHandle object that may be used to examine information about the transfer in a way familiar to libcurl users, with it’s GetInfoHandle.getinfo() and GetInfoHandle.getinfo_raw() methods.

Instances of Multi are shareable within a thread and although it is possible to use multiple instances it is recommended for performance and resource usage reasons to use only one.