VirusTotal v3 API Python client
raw JSON → 1.0.8 verified Mon Apr 27 auth: no python
A Python 3 implementation of the VirusTotal v3 API. Version 1.0.8 provides an object-oriented interface to the VirusTotal API, supporting files, URLs, domains, IPs, comments, and analyses. The library is in active development with a focus on ease of use.
pip install virustotal3 Common errors
error ModuleNotFoundError: No module named 'virustotal3' ↓
cause Library not installed or installed in a different Python environment.
fix
Run 'pip install virustotal3' in the correct environment or use a virtual environment.
error virustotal3.errors.VirusTotalAPIError: (403) Forbidden ↓
cause Invalid or missing API key, or the key does not have access to the requested resource.
fix
Verify your API key is correct and has the required permissions. Use os.getenv('VT_API_KEY') to ensure it's set.
Warnings
gotcha API key must be provided as a string; the library does not load from environment variables automatically. ↓
fix Export VT_API_KEY as an environment variable and pass it explicitly.
gotcha The library uses synchronous HTTP requests (requests library). It is not async-compatible; use threading or a separate executor for concurrent calls. ↓
fix Use Python's concurrent.futures or asyncio with loop.run_in_executor.
gotcha File upload for large files may exceed default request timeout. The library does not expose timeout parameters directly. ↓
fix Consider chunked upload or increase timeout by modifying the underlying session (monkey-patch requests timeout).
Imports
- Virustotal
from virustotal3 import Virustotal
Quickstart
import os
from virustotal3 import Virustotal
api_key = os.environ.get('VT_API_KEY', 'your_api_key')
vt = Virustotal(api_key)
try:
info = vt.get_file_info('275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0f')
print(info)
except Exception as e:
print(f'Error: {e}')