How to scan a file for viruses in Python

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+

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 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.
# Scan a file for viruses
api_response = api_instance.scan_file(input_file)
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.

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store