Skip to main content

Recursively scans a directory and outputs a flat, LLM-friendly file tree

Project description

filescan

filescan is a lightweight Python tool for scanning filesystem structures and Python ASTs and exporting them as flat, graph-style representations.

Instead of nested trees, filescan produces stable lists of nodes with parent pointers, making the output:

  • easy to post-process
  • friendly for CSV / DataFrame / SQL pipelines
  • efficient for LLM ingestion and summarization

filescan can operate at two levels:

  • filesystem structure (directories & files)
  • Python semantic structure (modules, classes, functions, methods)

Both use the same flat graph design and export formats.

Features

Filesystem scanning

  • Recursive directory traversal
  • Flat node list with explicit parent_id
  • Deterministic ordering
  • Optional .gitignore-style filtering
  • CSV and JSON export

Python AST scanning

  • Module, class, function, and method detection
  • Nested functions and classes supported
  • Stable symbol IDs with parent relationships
  • Best-effort function signature extraction
  • First-line docstring capture

General

  • Shared schema + export model
  • Same API for filesystem and AST scanners
  • Usable as both a library and a CLI
  • Designed for automation, data pipelines, and AI workflows

Installation

pip install filescan

Or for development:

pip install -e .

Quick start (CLI)

Filesystem scan (default)

Scan the current directory and write a CSV:

filescan

Scan a specific directory:

filescan ./data

Export as JSON:

filescan ./data --format json

Specify output base path:

filescan ./data -o out/tree

This generates:

out/
├── tree.csv
└── tree.json

Python AST scan

Scan Python source files and extract symbols:

filescan ./src --ast

Export AST symbols as JSON:

filescan ./src --ast --format json

Custom output path:

filescan ./src --ast -o out/symbols

This generates:

out/
├── symbols.csv
└── symbols.json

Ignore rules (.fscanignore)

filescan supports gitignore-style patterns via pathspec.

Default behavior

  • If --ignore-file is provided → use it
  • Otherwise, look for:
./.fscanignore   (current working directory)

Ignore rules apply to:

  • filesystem scanning
  • AST scanning (Python files are skipped if ignored)

Example .fscanignore

.git/
.idea/
build/
dist/
__pycache__/
*.pyc

Output formats

Both filesystem and AST scans produce flat graphs with schema metadata.

Filesystem schema

Field Description
id Unique integer ID
parent_id Parent node ID (null for root)
type 'd' = directory, 'f' = file
name Base name
size File size in bytes (null for directories)

CSV example

# id: Unique integer ID for this node
# parent_id: ID of parent node, or null for root
# type: Node type: 'd' = directory, 'f' = file
# name: Base name of the file or directory
# size: File size in bytes; null for directories
id,parent_id,type,name,size
0,,d,data,
1,0,f,example.txt,128

Python AST schema

| Field | Description | | - | | | id | Unique integer ID for this symbol | | parent_id | Parent symbol ID (null for module) | | kind | module | class | function | method | | name | Symbol name | | module_path | File path relative to scan root | | lineno | Starting line number (1-based) | | signature | Function or method signature (best-effort) | | doc | First line of docstring, if any |

Nested functions and classes are represented naturally via parent_id.

Library usage

Filesystem scanner

from filescan import Scanner

scanner = Scanner(
    root="data",
    ignore_file=".fscanignore",
)

scanner.scan()
scanner.to_csv()    # -> ./data.csv
scanner.to_json()   # -> ./data.json

Python AST scanner

from filescan import AstScanner

scanner = AstScanner(
    root="src",
    ignore_file=".fscanignore",
    output="out/symbols",
)

scanner.scan()
scanner.to_csv()
scanner.to_json()

Programmatic access

nodes = scanner.scan()
print(len(nodes))

data = scanner.to_dict()

Why filescan?

Most filesystem and code structures are represented as deeply nested trees. While human-readable, they are verbose, hard to query, and inefficient for large-scale processing.

filescan represents both filesystems and codebases as flat graphs because this format is:

  • Compact and token-efficient Flat lists with numeric IDs consume far fewer tokens than recursive trees, making them ideal for LLM context windows.

  • Explicit and unambiguous All relationships are encoded directly via parent_id.

  • Easy to process Flat data works naturally with filtering, joins, grouping, and graph analysis.

This makes filescan especially suitable for:

  • SQL / Pandas / DuckDB pipelines
  • Static analysis and refactoring tools
  • Graph-based code understanding
  • LLM-based reasoning and summarization of projects

In short, filescan favors machine-friendly structure over visual trees, enabling scalable, AI-native workflows.

Development

The project uses a src/ layout.

Examples can be run without installation:

python examples/scan_data.py

Or as a module:

python -m examples.scan_data

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

filescan-0.0.4.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

filescan-0.0.4-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file filescan-0.0.4.tar.gz.

File metadata

  • Download URL: filescan-0.0.4.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for filescan-0.0.4.tar.gz
Algorithm Hash digest
SHA256 0b4a3283b8da4de75bb46a2f4e8558e57efeccd6e5cbd843c8ce8a815df5f413
MD5 0b85d2a3eee755217a3fad944c7c7d6c
BLAKE2b-256 bbf0bd18a3360e03ccdf42320fb7404a294e8a0bf0a5a7845214b1f247504f27

See more details on using hashes here.

Provenance

The following attestation bundles were made for filescan-0.0.4.tar.gz:

Publisher: publish.yml on DreamSoul-AI/filescan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file filescan-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: filescan-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for filescan-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6b3a431653330a05f180feeb8926dac1b584c7bc8d0897a84dfb350eb64e6d18
MD5 3c1bdd4a7f122835879d6012614376c3
BLAKE2b-256 8138b000f74ae67d6055b35ae35d597264af0cbdc04687615f6ee32c99a47ba5

See more details on using hashes here.

Provenance

The following attestation bundles were made for filescan-0.0.4-py3-none-any.whl:

Publisher: publish.yml on DreamSoul-AI/filescan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page