Clamd is a Python interface library for communicating with the ClamAV daemon (`clamd`). It allows Python applications to send files or streams to `clamd` for virus scanning. The current stable version is 1.0.2, with a low release cadence indicating maturity and stability, focusing on Python 3.7+.
pip install clamdVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to connect to the ClamAV daemon using a Unix domain socket, send a test string for scanning, and interpret the results. It includes basic error handling for common connection issues.
Ensure the ClamAV daemon (`clamd`) is installed, started, and configured to listen on the specified Unix socket path or network address. Check system logs (e.g., `journalctl -u clamd.service`) for daemon status.
Adjust file permissions for the clamd socket or ensure the Python process is running as a user or group that has access (e.g., `clamav` group). Alternatively, consider using `ClamdNetworkSocket` if network access is configured and appropriate for your security model.
Always check the dictionary structure. For stream scans, the key is typically 'stream'. The value is `('OK', None)` for clean files, or `('FOUND', 'VIRUS_NAME')` if a virus is detected. Example: `result = cd.scan(b'...')`; then access `result['stream'][0]` for status and `result['stream'][1]` for virus name.Always provide byte strings (e.g., `b'my data'`) when scanning data directly. If you have a Python string, convert it using `.encode('utf-8')` or another appropriate encoding.Ensure the `clamd` service is running (`sudo systemctl start clamav-daemon` or `sudo service clamav-daemon start`). Verify `clamd.conf` for correct `LocalSocket` or `TCPAddr`/`TCPSocket` settings and check firewall rules to allow connections to the daemon's port (default 3310) or socket.
Install the `clamd` library using pip: `pip install clamd`
Grant read permissions to the user under which `clamd` runs for the target files/directories. If AppArmor or SELinux is active, review and adjust their profiles to allow `clamd` access to the relevant paths.
Edit the `clamd.conf` file (typically `/etc/clamav/clamd.conf`) to increase the `StreamMaxLength` value to accommodate larger streams, then restart the `clamd` service. Alternatively, ensure the data stream being sent is within the configured limit.
No dependency data recorded yet.