vt-py is the official Python client library for the VirusTotal API v3. This library enables interaction with the VirusTotal REST API v3 to automate security workflows, including scanning files and URLs, retrieving comprehensive information about various entities (files, URLs, domains), managing VirusTotal Intelligence searches, LiveHunt rulesets, and launching Retrohunt jobs. It is actively maintained with regular releases.
pip install vt-pyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to fetch information about a file using its SHA256 hash. It initializes an asynchronous `vt.Client` with an API key from an environment variable, retrieves a `vt.Object` representing the file, and prints some of its attributes. The client is automatically closed using `async with`.
Upgrade Python to 3.8 or newer, or downgrade `vt-py` to `<0.21.0`.
Update code to treat `vt.Object` attributes as standard dictionaries. If on older versions, ensure attributes are explicitly converted or accessed as plain dicts before serialization.
Ensure `vt-py` asynchronous calls are executed within an `asyncio` event loop. For standalone scripts, use `asyncio.run()`. For integration into existing sync applications, consider `nest_asyncio` or carefully manage event loop contexts.
Always use the client within an `async with vt.Client(...)` block, which handles automatic closing, or explicitly call `await client.close()` after all operations are complete.
Familiarize yourself with the official VirusTotal API v3 documentation to understand endpoints, object structures, and request/response formats when using `vt-py`.