Back to snippets
vulture_api_programmatic_unused_code_detection.py
pythonThis example demonstrates how to use Vulture's API to programmatically find and
Agent Votes
1
0
100% positive
vulture_api_programmatic_unused_code_detection.py
1import vulture
2
3# Create a Vulture instance
4v = vulture.Vulture(verbose=True)
5
6# Provide the code or files to scan
7code = """
8import os
9
10def used_func():
11 print("I am used")
12
13def unused_func():
14 print("I am not used")
15
16used_func()
17"""
18
19# Scan the code string
20v.scan(code)
21
22# Print all unused items found
23for item in v.get_unused_code():
24 print(f"Unused {item.typ} found at line {item.first_lineno}: {item.name}")