Philosophy: Human-Controlled, Pattern-Driven Code Auditing.
Code Archaeologist is a lightweight static analysis script built for developers who maintain a "Local Source of Truth." In an era of fast AI-generated code, it is designed for small teams and solo builders who want to keep cleanup human-controlled while navigating modern Python codebases.
Instead of mass-deleting code, it treats a repository like an archaeological dig—surfacing potential "artifacts" (uncalled functions, leftover helpers, and legacy code) in a confidence report so you can inspect them and decide what stays or goes.
Rather than maintaining an exhaustive database of every framework, the scanner combines ast analysis with practical heuristics:
-
Embedded Config (
EMBEDDED_CONFIG_JSON): Any function names listed inignore_functionsare treated as protected (0%dead confidence), and directories inignore_dirsare skipped during traversal. -
Decorator Rule: Functions with decorators (such as routes, tasks, or registered hooks) are treated as entry points (
0%dead confidence). -
Call Tracking: Function and method names seen in
ast.Callnodes are marked as used (0%dead confidence).
For functions not already protected at 0%, naming patterns adjust the score:
-
Dunder or Capitalised Names: Names starting with
__or an uppercase letter start at100and drop by60points (e.g.,40%), treating special/internal/component-style names more cautiously. -
Leading Underscore (
_helper): Adds+10(capped at100%), since private helpers are still worth checking when uncalled.
Every reported item gets a Dead Confidence percentage showing how likely an uncalled function is to be unused/dead:
-
100%: Uncalled, undecorated function with no special dunder/capitalised protection—highest priority to review.
-
40%: Uncalled, undecorated dunder or capitalised name—lower likelihood of being dead code, worth a quick check.
-
0% (omitted from report): Ignored via
EMBEDDED_CONFIG_JSON, decorated, or matched in recorded call names.
code_archaeologist/
├── scanner.py # Standalone single-file Archaeologist script
├── archaeology_report.json # Generated JSON report (created when run)
└── [Your Project Files] # The "Dig Site" being scanned
scanner.py runs as a single, standalone script using only the Python standard library—no pip install or separate configuration files required.
- Python 3.10+ (tested on Python 3.13.7)
- A project directory containing
.pyfiles
- Copy
scanner.pyinto the root folder of the project you want to inspect. - Open your terminal in that folder and run:
python scanner.py- Review the table printed to your terminal and check
archaeology_report.jsonin the same folder.
No external archaeo.json file is needed. Edit EMBEDDED_CONFIG_JSON directly inside scanner.py whenever you want to ignore specific function names or skip extra directories:
EMBEDDED_CONFIG_JSON = """
{
"ignore_functions": [
"serve_layout",
"update_dashboard"
],
"ignore_dirs": [
".venv",
"build",
"dist",
"migrations"
]
}
"""-
Zero Extra Files in Target Repos: Drop in
scanner.py, run it, and tweakEMBEDDED_CONFIG_JSONright inside the script without creating extra config files. -
Zero External Dependencies: Uses Python's standard library (
ast,json,logging,pathlib,typing). -
Local & Machine-Readable Output: Prints a quick console summary and writes
archaeology_report.jsonfor easy review or feeding into cleanup workflows.
- 100% Local: No data leaves your machine.
- Read-Only AST Inspection: Parses
.pyfiles withast.parse()rather than importing or executing your application code.
-
CLI Path & Output Options: Support target directory and output path flags via
argparsesoscanner.pycan scan other folders without copying or renaming files manually. -
File Pattern Ignores (
ignore_files): Support glob-style filename patterns (usingfnmatch) insideEMBEDDED_CONFIG_JSONto skip specific files without ignoring entire directories. -
Confidence Filter (
--min-confidence): Filter terminal and JSON report output to items meeting a minimum dead-confidence threshold during triage.