Python SDK
The security.dev Python SDK provides a simple way to integrate our security APIs into your Python applications.
Installation
Section titled “Installation”Install the SDK:
Client Initialization
Section titled “Client Initialization”from securitydev import SecurityClient # Initialize with your API key client = SecurityClient(key="<your_app_key>")
User Intel API
Section titled “User Intel API”The IP Intel API is accessible through the user_intel
property of the client.
Get information about an email address:
import securitydev email = "[email protected]" e = securitydev.user_intel.email(email) if e.is_disposable: print(f"{email} is a diposable mail from {e.providers}")
IP Intel API
Section titled “IP Intel API”The IP Intel API is accessible through the ip_intel
property of the client.
Geolocate
Section titled “Geolocate”Get geolocation information for an IP address:
geo = client.ip_intel.geolocate("9.9.9.9") # Access geolocation data print(geo.country.name) # "United States" print(geo.city.name) # "Ashburn" print(geo.location.latitude) # 39.0438 print(geo.location.longitude) # -77.4874
Reputation
Section titled “Reputation”Get reputation data for an IP address:
rep = client.ip_intel.reputation("9.9.9.9") # Access reputation data print(rep.is_abuser) # False print(rep.is_tor_exit) # False print(rep.is_proxy) # False
Common Use Cases
Section titled “Common Use Cases”Blocking TOR Exit Nodes
Section titled “Blocking TOR Exit Nodes”from securitydev import SecurityClient client = SecurityClient(key="<your_app_key>") # Get IP reputation data rep = client.ip_intel.reputation(request.ip) # Block TOR exit nodes if rep.is_tor_exit: raise Http404("Not Found")
Geolocation-Based Access Control
Section titled “Geolocation-Based Access Control”from securitydev import SecurityClient client = SecurityClient(key="<your_app_key>") # Get IP geolocation data geo = client.ip_intel.geolocate(request.ip) # Restrict access to specific countries allowed_countries = ["US", "CA", "GB"] if geo.country.code not in allowed_countries: return HttpResponse("Service not available in your region", status=403)