Scanning a Google Cloud Platform (GCP) Storage File for Viruses in Python
Looking to scan your GCP file for viruses and other threats? We’re here to help with that. Our cloud storage virus scan API peruses a continuously updated database of over 17 million virus and malware signatures. All you need to utilize the API is the applicable bucket name, object/file name, and JSON credential file from Google Cloud, as well as the information below.

For our first step, run this command to install the SDK:
pip install cloudmersive-virus-api-client
Next, we are instancing our API using a key and calling the ScanCloudStorage function from the instance using the following code:
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'# create an instance of the API class
api_instance = cloudmersive_virus_api_client.ScanCloudStorageApi(cloudmersive_virus_api_client.ApiClient(configuration))
bucket_name = 'bucket_name_example' # str | Name of the bucket in Google Cloud Storage
object_name = 'object_name_example' # str | Name of the object or file in Google Cloud Storage
json_credential_file = '/path/to/inputfile' # file | Service Account credential for Google Cloud stored in a JSON file.try:
# Scan an Google Cloud Platform (GCP) Storage file for viruses
api_response = api_instance.scan_cloud_storage_scan_gcp_storage_file(bucket_name, object_name, json_credential_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling ScanCloudStorageApi->scan_cloud_storage_scan_gcp_storage_file: %s\n" % e)
And boom! The scan will return an immediate response informing you of the virus name (if found) or assuring you that your file is indeed free from threats.