Registry / http-networking / pycurl

pycurl

JSON →
library7.47.0pypypi✓ verified 26d ago

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 pycurl
INSTALL
IMPORT
SIG · PYCURL
P
pycurl
http-networkingpythonv7.47.0
Install
1.7s avg
Import
48ms
Disk
30MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.47.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.038s · 32MB
30MB installed
● package 30MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pycurl
import pycurl
Curl
import pycurl c = pycurl.Curl()
BytesIO
from io import BytesIO
Commonly used with pycurl.WRITEDATA to capture response body in memory.

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.

import pycurl from io import BytesIO def fetch_url(url): buffer = BytesIO() c = pycurl.Curl() c.setopt(c.URL, url) c.setopt(c.WRITEDATA, buffer) # Optional: For HTTPS, use certifi for certificate bundle # import certifi # c.setopt(c.CAINFO, certifi.where()) try: c.perform() status_code = c.getinfo(pycurl.RESPONSE_CODE) response_body = buffer.getvalue().decode('utf-8', errors='ignore') print(f"Status Code: {status_code}") print(f"Response Body (first 200 chars):\n{response_body[:200]}") except pycurl.error as e: print(f"PycURL error: {e}") finally: c.close() # Example usage fetch_url('https://httpbin.org/get')
pycurl --version
Debug
Known issues
gotchaPycURL is a wrapper around `libcurl`, a system library. Installing PycURL via pip often requires `libcurl` and its development headers (e.g., `libcurl4-openssl-dev` on Debian/Ubuntu, `curl` on macOS via Homebrew) to be present on your system. Without these, installation may fail or lead to runtime errors, especially when building from source.
fix
Ensure `libcurl` and its development packages are installed on your system before `pip install pycurl`.
affects: All versions
gotchaSSL backend mismatches can cause runtime `ImportError` (e.g., `pycurl: libcurl link-time ssl backend (...) is different from compile-time ssl backend (...)`). This occurs if PycURL is built against a different SSL library than what `libcurl` uses at runtime.
fix
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.
affects: All versions, particularly on custom builds or environments with multiple SSL libraries.
gotchaPycURL returns all network data as `bytes` objects. For text content, you must explicitly decode these `bytes` to `str` (e.g., using `.decode('utf-8')`). Conversely, when passing non-ASCII Unicode strings to `setopt` or `READFUNCTION`, they must first be encoded into `bytes` to avoid `UnicodeEncodeError` or `pycurl.error` (e.g., 'read function error/data error').
fix
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.
affects: Python 3.x
deprecatedWhile `c.setopt(c.WRITEFUNCTION, buffer.write)` still works, as of PycURL 7.19.3, `c.setopt(c.WRITEDATA, buffer)` is generally preferred and simpler as it accepts any Python object with a `write` method (like `io.BytesIO`).
fix
Prefer `c.setopt(c.WRITEDATA, buffer)` over `WRITEFUNCTION` when providing a simple writeable object to capture response data.
affects: PycURL 7.19.3+
breakingThe `DEBUGFUNCTION` callback on Python 3 now expects its argument to be `bytes` instead of a (Unicode) `string`.
fix
Update `DEBUGFUNCTION` implementations on Python 3 to handle `bytes` arguments.
affects: PycURL 7.19.5.2 and later (on Python 3)
breakingThe `CURLMOPT_*` option constants, related to the multi interface, were moved from the `Easy` class to the `Multi` class. They remain available in the top-level `pycurl` module for backward compatibility.
fix
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`).
affects: PycURL 7.19.5.2 and later
Errors
Common errors & fixes
_curl.c: fatal error: curl/curl.h: No such file or directory
PycURL requires `libcurl` development headers (e.g., `libcurl-devel` or `libcurl4-openssl-dev`) to be installed on the system during its compilation.
fix
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`.
ModuleNotFoundError: No module named 'pycurl'
The `pycurl` library is not installed in the Python environment where the code is being run.
fix
pip install pycurl
error: 'curl-config' is not found
The `curl-config` utility, which is part of the `libcurl` development package, is missing from the system's PATH, preventing `pycurl` from configuring itself correctly during installation.
fix
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`.
pycurl.error: (60, "SSL certificate problem: unable to get local issuer certificate")
PycURL cannot verify the SSL certificate of the remote server, often due to an outdated or missing CA certificate bundle on the system or incorrect path configuration.
fix
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).
Upgrade
Version history
7.47.0latest on PyPI · released Jun 29, 2026
Audit
Dependencies
libcurlrequiredPycURL is a C extension that wraps the system's libcurl library. Its development headers are often required for successful installation, especially from source.
certifioptionalRecommended for managing SSL certificate bundles, especially when performing HTTPS requests.
Agent activity
9 hits · last 30 days
node
8
Resources