scantree
Flexible recursive directory iterator: scandir meets glob("**", recursive=True)
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 scantreeuv
uv add scantreepoetry
poetry add scantreeInstalling 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
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
ignore-pythonProvides fast recursive directory traversal…
unclear · top 15,000 on PyPI
scandirProvides faster directory iteration and…
permissive · top 5,000 on PyPI
wcmatchwcmatch provides enhanced file pattern matching…
permissive · top 1,000 on PyPI
glob2glob2 extends Python's built-in glob module…
permissive · top 5,000 on PyPI
pathmagicProvides File and Dir classes that wrap…
permissive · top 15,000 on PyPI
globmatchMatches file paths against glob patterns…
permissive · top 15,000 on PyPI
colcon-recursive-crawlA colcon-core extension that recursively crawls…
permissive · top 15,000 on PyPI
xdg-base-dirsProvides functions to retrieve XDG Base…
permissive · top 15,000 on PyPI
pathtoolsProvides pattern matching and utility functions…
permissive · top 15,000 on PyPI
path.pyProvides Path objects that wrap filesystem…
permissive · top 15,000 on PyPI