The clamav-client library (current version 0.7.2) provides a Python client for interacting with a ClamAV antivirus daemon, allowing applications to scan files and streams for viruses. It is actively maintained, with releases typically tied to feature updates, bug fixes, and Python version support.
pip install clamav-clientVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `ClamAVClient`, ping the server to verify connectivity, and scan a local file using `scan_stream`. It includes error handling for common connection and client-specific issues.
Upgrade your Python environment to 3.9 or newer, or pin `clamav-client<0.7.0` (not recommended).
Replace calls to `client.scan_file(filepath)` with `with open(filepath, 'rb') as f: client.scan_stream(f)`.
Ensure the ClamAV daemon (`clamd`) is running, listening on the correct IP address (e.g., `0.0.0.0` or `127.0.0.1`), and the firewall is not blocking the port (default 3310).
Increase the `timeout` parameter during `ClamAVClient` initialization (e.g., `ClamAVClient(..., timeout=60.0)`). For very large files, consider splitting them or processing them in chunks if your ClamAV setup supports it, though `scan_stream` is generally efficient for this.