Using the library importlab and grep on a shell prompt from the project's root folder: importlab --tree path/to/file.py | grep -E '^\s+[^::]*py$'