How to Check a URL for Safety Threats in Python

2 min readMar 8, 2021

With cyber attacks running rampant across the web, you can’t always trust that a link you click is going to lead to a secure site. In this post, we will discuss how to use an API in Python to check if a URL is at risk of being a safety concern through malware, unwanted software, or social engineering threats such as phishing. This process is an easy and efficient step you can implement to protect both your employees and your users.

To begin the operation, we will run this command to install the client:

pip install cloudmersive-validate-api-client

Following the installation, we can use the following code to instance the API and call the function:

from __future__ import print_function
import time
import cloudmersive_validate_api_client
from import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_validate_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_validate_api_client.DomainApi(cloudmersive_validate_api_client.ApiClient(configuration))
request = cloudmersive_validate_api_client.UrlSafetyCheckRequestFull() # UrlSafetyCheckRequestFull | Input URL request
# Check a URL for safety threats
api_response = api_instance.domain_safety_check(request)
except ApiException as e:
print("Exception when calling DomainApi->domain_safety_check: %s\n" % e)

The only parameters that need to be input are the URL you’re checking and your personal API key. If you don’t already have an API key, you can obtain one by registering for a free account on the Cloudmersive website; this will give you access to 800 monthly calls.




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