Registry / http-networking / vt-py
library0.22.0pypypi✓ verified 84d ago

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-py
INSTALL
IMPORT
SIG · VT-PY
V
vt-py
http-networkingpythonv0.22.0
Install
4.1s avg
Import
596ms
Disk
27MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.22.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.625s · 27.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 4.1s · import 0.567s · 30MB
27MB installed
● package 27MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
from vt import Client
import vt client = vt.Client(api_key)

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`.

import os import asyncio import vt async def get_file_info(api_key: str, file_hash: str): """Fetches information about a file hash from VirusTotal.""" async with vt.Client(api_key) as client: try: file_obj = await client.get_object(f"/files/{file_hash}") print(f"File SHA256: {file_obj.sha256}") print(f"File Size: {file_obj.size} bytes") print(f"Detection Stats: {file_obj.last_analysis_stats}") except vt.APIError as e: print(f"VirusTotal API error: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") if __name__ == "__main__": VIRUSTOTAL_API_KEY = os.environ.get('VIRUSTOTAL_API_KEY', '') if not VIRUSTOTAL_API_KEY: print("Please set the VIRUSTOTAL_API_KEY environment variable.") else: # Example SHA256 hash of an EICAR test file example_hash = "275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0f" asyncio.run(get_file_info(VIRUSTOTAL_API_KEY, example_hash))
Debug
Known issues
breakingPython 3.7 support was officially dropped in `vt-py` version 0.21.0. Users on Python 3.7 or older will need to upgrade their Python version or pin `vt-py` to a version prior to 0.21.0.
fix
Upgrade Python to 3.8 or newer, or downgrade `vt-py` to `<0.21.0`.
affects: >=0.21.0
breakingIn `vt-py` v0.20.0, the `WhistleBlowerDict` (a subclass of `collections.UserDict`) used internally for `vt.Object` attributes was converted to a plain Python `dict`. Code relying on `UserDict` specific behaviors or encountering 'Object of type WhistleBlowerDict is not JSON serializable' errors in older versions should be updated.
fix
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.
affects: >=0.20.0
gotchaThe `vt-py` library is built around `asyncio`. Running client methods in synchronous code or within existing event loops (e.g., in some web frameworks or cloud functions) without proper `asyncio` context can lead to `RuntimeError: There is no current event loop in thread...` errors.
fix
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.
affects: All
gotchaIt is crucial to explicitly close the `vt.Client` instance to release underlying network resources (like TCP connections) when it's no longer needed. Not doing so can lead to resource leaks and potential runtime warnings/errors.
fix
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.
affects: All
gotchaThe `vt-py` library is designed as a relatively low-level wrapper around the VirusTotal API v3. Users are expected to have a good understanding of the VirusTotal API v3 concepts and REST endpoint paths, as the library mirrors the API structure rather than providing a high level of abstraction.
fix
Familiarize yourself with the official VirusTotal API v3 documentation to understand endpoints, object structures, and request/response formats when using `vt-py`.
affects: All
Upgrade
Version history
0.22.0latest on PyPI · released Oct 28, 2025
Audit
Dependencies
aiohttprequiredCore library for asynchronous HTTP requests.
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
1
Resources
vt-py — pip install vt-py · libregistry