PycURL is a Python interface to the `libcurl` library, providing fast and feature-rich capabilities for network operations. It supports numerous protocols including HTTP, HTTPS, FTP, and more, exposing most of `libcurl`'s functionality like SSL, authentication, and proxy options. PycURL is often chosen for performance-critical applications and I/O multiplexing due to its speed. The current version is 7.45.7, with releases occurring periodically to incorporate `libcurl` updates and security fixes.
pip install pycurlVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to perform a basic GET request using PycURL. It initializes a Curl object, sets the URL, and uses `io.BytesIO` to capture the response body. Error handling for PycURL specific errors is included. It also highlights an optional step for using `certifi` for robust HTTPS certificate verification.
Ensure `libcurl` and its development packages are installed on your system before `pip install pycurl`.
During installation, explicitly tell `setup.py` which SSL backend to use via the `PYCURL_SSL_LIBRARY` environment variable (e.g., `export PYCURL_SSL_LIBRARY=openssl pip install pycurl`) or `setup.py` command-line options.
Always decode received `bytes` to `str` for text, and encode `str` to `bytes` when sending non-ASCII data to PycURL. Use `errors='ignore'` or `errors='replace'` during decoding if dealing with unknown/malformed encodings.
Prefer `c.setopt(c.WRITEDATA, buffer)` over `WRITEFUNCTION` when providing a simple writeable object to capture response data.
Update `DEBUGFUNCTION` implementations on Python 3 to handle `bytes` arguments.
Access `CURLMOPT_*` constants either directly from the `pycurl` module (e.g., `pycurl.CURLMOPT_PIPELINING`) or from a `CurlMulti` instance (e.g., `multi_handle.CURLMOPT_PIPELINING`).
sudo apt-get install libcurl4-openssl-dev python3-dev (for Debian/Ubuntu) or sudo yum install libcurl-devel python3-devel (for RHEL/CentOS) before `pip install pycurl`.
pip install pycurl
Install the `libcurl` development package: `sudo apt-get install libcurl4-openssl-dev` (Debian/Ubuntu) or `sudo yum install libcurl-devel` (RHEL/CentOS), then retry `pip install pycurl`.
Update your system's CA certificates (`sudo apt-get update && sudo apt-get install ca-certificates` on Debian/Ubuntu), or for testing/development, temporarily disable SSL verification by setting `c.setopt(pycurl.SSL_VERIFYPEER, 0)` and `c.setopt(pycurl.SSL_VERIFYHOST, 0)` (use with caution in production).