Registry / auth-security / clamav-client

clamav-client

JSON →
library0.7.2pypypi✓ verified 87d ago

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-client
INSTALL
IMPORT
SIG · CLAMAV-CLIENT
C
clamav-client
auth-securitypythonv0.7.2
Install
1.5s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.7.2 · 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.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

clamd
✓ from clamav_client import clamd
✗ from clamav_client import ClamAVClient
get_scanner
✓ from clamav_client import get_scanner
scanner
✓ from clamav_client import scanner

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.

import os from clamav_client import ClamAVClient from clamav_client.exceptions import ClamAVClientError # Configure ClamAV server details, use environment variables for production CLAMAV_HOST = os.environ.get('CLAMAV_HOST', '127.0.0.1') CLAMAV_PORT = int(os.environ.get('CLAMAV_PORT', '3310')) CLAMAV_TIMEOUT = float(os.environ.get('CLAMAV_TIMEOUT', '10.0')) client = ClamAVClient(host=CLAMAV_HOST, port=CLAMAV_PORT, timeout=CLAMAV_TIMEOUT) try: # Ping the ClamAV server to check connectivity version = client.ping() print(f"Connected to ClamAV server (version: {version})") # Create a dummy file for scanning dummy_file_path = "test_file.txt" with open(dummy_file_path, "w") as f: f.write("This is a clean test file.") # Scan a local file print(f"Scanning file: {dummy_file_path}") with open(dummy_file_path, "rb") as f: scan_result = client.scan_stream(f) if scan_result.is_infected: print(f"File '{dummy_file_path}' is infected! Virus: {scan_result.virus_name}") else: print(f"File '{dummy_file_path}' is clean.") # Clean up the dummy file os.remove(dummy_file_path) except ClamAVClientError as e: print(f"Error communicating with ClamAV server: {e}") except ConnectionRefusedError: print(f"Connection refused. Is ClamAV running at {CLAMAV_HOST}:{CLAMAV_PORT}?") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingPython 3.8 support was dropped in version 0.7.0. The library now requires Python 3.9 or higher.
fix
Upgrade your Python environment to 3.9 or newer, or pin `clamav-client<0.7.0` (not recommended).
affects: >=0.7.0
breakingThe `ClamAVClient.scan_file` method was renamed to `ClamAVClient.scan_stream` in version 0.6.0 to better reflect its underlying streaming behavior.
fix
Replace calls to `client.scan_file(filepath)` with `with open(filepath, 'rb') as f: client.scan_stream(f)`.
affects: >=0.6.0
gotchaThe ClamAV server must be running and accessible at the specified host and port. Connection issues (e.g., 'Connection refused') are common if the server is down or incorrectly configured.
fix
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).
affects: All
gotchaLarge files can cause `ClamAVClientError` with a timeout message if the ClamAV server takes too long to respond. The `timeout` parameter in `ClamAVClient` constructor controls the client-side timeout.
fix
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.
affects: All
Upgrade
Version history
0.7.2latest on PyPI · released Mar 5, 2026
Audit
Dependencies
requestsrequiredUsed for underlying HTTP communication with the ClamAV server.
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
clamav-client — pip install clamav-client · libregistry