How to scan a file for viruses in Python
1 min readAug 23, 2019
Let’s take a look at how to easily set up automatic virus scanning using one of our APIs. Start by installing the client:
pip install git+https://github.com/Cloudmersive/Cloudmersive.APIClient.Python.Virus.git
Now call scan_file and input the file you wish to be scanned:
from __future__ import print_function
import time
import cloudmersive_virus_api_client
from cloudmersive_virus_api_client.rest import ApiException
from pprint import pprint# Configure API key authorization: Apikey
configuration = cloudmersive_virus_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API class
api_instance = cloudmersive_virus_api_client.ScanApi(cloudmersive_virus_api_client.ApiClient(configuration))
input_file = '/path/to/file' # file | Input file to perform the operation on.try:
# Scan a file for viruses
api_response = api_instance.scan_file(input_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling ScanApi->scan_file: %s\n" % e)
And we’re done! Our return will include whether the file came up positive and its identity.