Skip to content

Virus Scanner

Document Processing Orchestrator Virus Scanner Package.

Modules:

Name Description
BaseVirusScanner

Abstract base class for virus scanners.

ClamAVVirusScanner

Virus scanner using a networked ClamAV daemon.

ClamAVMode

ClamAV scanning modes.

MaliciousSourceError

Exception raised when a source is detected as malicious.

BaseVirusScanner

Bases: ABC

Base class for virus scanners.

scan(source, **kwargs) abstractmethod

Scan a source for viruses using the configured antivirus backend.

If a virus is found, a MaliciousSourceError is raised to prevent further processing. If the source is clean, the method completes silently.

Parameters:

Name Type Description Default
source str

The input source to scan. Typically a file path, but may support other types in the future.

required
**kwargs Any

Additional keyword arguments for customization.

{}

Raises:

Type Description
MaliciousSourceError

If the source is flagged as malicious.

ClamAVMode

Bases: StrEnum

ClamAV scanning modes.

INSTREAM streams file bytes to the ClamAV daemon. SCAN scans a file path that is visible to the ClamAV daemon.

ClamAVVirusScanner(host, port, timeout=None, scan_mode=ClamAVMode.INSTREAM)

Bases: BaseVirusScanner

Virus scanner using a networked ClamAV daemon.

Attributes:

Name Type Description
clamd_client ClamdNetworkSocket

Network client used to talk to the ClamAV daemon.

scan_mode ClamAVMode

Scanning mode, either instream or scan.

Initialize the ClamAVVirusScanner.

Parameters:

Name Type Description Default
host str

The hostname of the ClamAV server.

required
port int

The port of the ClamAV server.

required
timeout int | None

The timeout for the ClamAV connection. Defaults to None.

None
scan_mode ClamAVMode | str

The scanning mode (INSTREAM or SCAN). Defaults to ClamAVMode.INSTREAM.

INSTREAM

Raises:

Type Description
ImportError

If the clamav extra is not installed.

ValueError

If scan_mode is not a valid ClamAVMode.

scan(source, **kwargs)

Scan the specified source for viruses using ClamAV.

INSTREAM streams file bytes to ClamAV. SCAN asks ClamAV to read a file path that is mounted on the daemon. A clean file completes silently. A FOUND result raises MaliciousSourceError. ClamAV ERROR status and unexpected scan failures are logged without raising, so a scanner outage does not stop document processing.

Parameters:

Name Type Description Default
source str

The input source to scan.

required
**kwargs Any

Additional keyword arguments. Unused.

{}

Raises:

Type Description
MaliciousSourceError

If the source is flagged as malicious.

MaliciousSourceError(message)

Bases: Exception

Exception raised when a source is detected to be malicious during virus scanning.

Initialize the MaliciousSourceError class.

Parameters:

Name Type Description Default
message str

The message to display when the exception is raised.

required