pyClamd - use ClamAV antivirus from Python

pyClamd is a portable Python module to use the ClamAV antivirus engine on Windows, Linux, MacOSX and other platforms. It requires a running instance of the clamd daemon. pyClamd is more portable than pyClamAV because it does not need to be compiled, so it works on Windows.

This is a slightly improved version of pyClamd v0.1.1 originally created by Alexandre Norman and published on his website: http://xael.org/norman/python/pyclamd/

Improvements from version 0.1.1 to 0.2.0:

  • added option to set a timeout on scans
  • fixed warning due to string exceptions with Python 2.5

License:

pyClamd is released as open-source software under the GPLv2 license.

Download:

Click on the link below to download the zip file.

How to install clamd:

 

How to run clamd as a service on Windows:
See http://www.andornot.com/blog/post/How-to-set-up-ClamAV-as-a-Windows-Serv... or http://www.google.com/search?q=clamd+windows+service

There used to be instructions on http://www.asspsmtp.org/wiki/ClamAV_Win32 to use either runclamd or the NJH Power Tools, but the website is not available anymore.

How to use pyClamd:

See source code or Alexandre Norman's website: http://xael.org/norman/python/pyclamd/

Here is an example on Unix:

$ python
>>> import pyclamd
>>> pyclamd.init_unix_socket('/tmp/clamd.socket')
>>> pyclamd.ping()
True
>>> pyclamd.version()
'ClamAV 0.95.3/10512/Thu Mar  4 14:17:23 2010'
>>> pyclamd.scan_stream(pyclamd.EICAR)
{'stream': 'Eicar-Test-Signature FOUND'}
>>> pyclamd.scan_stream('a clean string')
>>> pyclamd.scan_file('/tmp/clean.txt')
>>> f=open('/tmp/eicar.bin','wb')
>>> f.write(pyclamd.EICAR)
>>> f.close()
>>> pyclamd.scan_file('/tmp/eicar.bin')
{'/tmp/eicar.bin': 'Eicar-Test-Signature'}
>>> import os
>>> os.remove('/tmp/eicar.bin')
>>> 

 

 

AttachmentSize
pyclamd-0.2.0.zip11.44 KB