skillfed

scantree

Flexible recursive directory iterator: scandir meets glob("**", recursive=True)

scantree v0.0.4 13.3M downloads/30d#1,286 on PyPI16
Permissive license MIT Active released

What it is and what it does

scantree is a recursive directory scanner that combines the functionality of os.scandir with glob-style pattern matching. It builds an in-memory representation of a file tree, allowing repeated access without re-scanning the filesystem. The library extends the standard os.DirEntry interface with additional path information (real paths, paths relative to the recursion root) and includes built-in detection and handling of cyclic symlinks.

The package is typically used when you need flexible filtering of directory contents—such as matching files by wildcard patterns or custom predicates—while also needing efficient access to file metadata or the ability to traverse and aggregate information across the tree structure. It handles symlinks gracefully, distinguishing between regular symlinks and cycles that would otherwise cause infinite recursion.

Use it for:

  • Find all files matching a pattern (e.g., '*.txt') across nested directories with relative and absolute path access
  • Build an in-memory representation of a directory tree for repeated queries without re-scanning the filesystem
  • Detect and safely handle cyclic symlinks during recursive directory traversal
  • Aggregate statistics or metadata across a file tree using the apply() method with custom file and directory handlers
  • Compare directory structures before and after filesystem operations using tree equality checks

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Recursively scans directories with flexible filtering, wildcard matching, and in-memory tree representation, providing extended file metadata and cyclic symlink detection.

Yes. scantree is actively maintained, has no known vulnerabilities, minimal dependencies, and solves a real problem—flexible directory iteration with symlink safety and in-memory caching. Use it when you need pattern-based directory filtering or repeated tree access; skip it if you only need a single pass over the filesystem.

Install

scantree on PyPI

pip

pip install scantree

uv

uv add scantree

poetry

poetry add scantree

Installing scantree

Before you install

Low friction: pure Python wheel with only two lightweight runtime dependencies (attrs and pathspec). Active maintenance with last commit on 2026-04-13 and latest release on 2024-08-03.

License in practice

MIT license is permissive, allowing unrestricted use, modification, and distribution with minimal legal constraints.

Quickstart

from scantree import scantree, RecursionFilter

tree = scantree('/path/to/dir', RecursionFilter(match=['*.txt']))
print([path.relative for path in tree.filepaths()])

Verify before relying

  • Performance characteristics when scanning very large directory trees or handling thousands of files
  • Memory overhead of the in-memory tree representation compared to streaming alternatives

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 2 — attrs, pathspec
Maintenance actively maintained — 741 days since the last release
Last repo commit
First released
Downloads 13,323,146/month — #1,286 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: scantree-0.0.4-py3-none-any.whl

Tags

recursive directory iteratordirectory tree scanningglob with filteringwildcard path matchingsymlink detectionfile tree representationdirectory traversal
filesystemdirectory-scanning

More Utilities packages