VirusTotal Graph API Python Client
raw JSON → 2.2.0 verified Fri May 01 auth: no python
The official Python client library for VirusTotal Graph API (version 2.2.0). Enables querying VirusTotal's graph database using Cypher-like queries. Release cadence is ad-hoc.
pip install vt-graph-api Common errors
error ImportError: No module named vt_graph_api ↓
cause The package is installed but Python cannot find the module. Possibly installed in a different environment or using wrong import path.
fix
Ensure you have installed 'vt-graph-api' via pip (not 'vt_graph_api') and are importing from 'vt_graph_api'.
error AttributeError: 'VTGraphAPI' object has no attribute 'query' ↓
cause Using an older version (<2.0.0) where 'query' method did not exist.
fix
Upgrade to version >=2.0.0: pip install --upgrade vt-graph-api
error HTTPError: 401 Client Error: Unauthorized ↓
cause Invalid or missing API key.
fix
Set the VT_API_KEY environment variable or pass a valid API key to the constructor.
Warnings
breaking Python 2 support was dropped in v2.0.0. Use Python 3.6+. ↓
fix Upgrade to Python 3.6+ and use vt-graph-api >=2.0.0.
gotcha The 'query' method returns raw dict results. It does not validate queries before sending. ↓
fix Always wrap in try/except and validate your Cypher syntax beforehand.
deprecated The method 'get' is deprecated since v2.0.0 in favor of 'query'. ↓
fix Replace 'get' calls with 'query'.
Imports
- VTGraphAPI wrong
import vt_graph_apicorrectfrom vt_graph_api import VTGraphAPI
Quickstart
from vt_graph_api import VTGraphAPI
import os
api_key = os.environ.get('VT_API_KEY', '')
client = VTGraphAPI(api_key)
try:
result = client.query("MATCH (node:file {sha256: '275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0f'}) RETURN node")
print(result)
except Exception as e:
print(f"Error: {e}")