scandir
scandir, a better directory iterator and faster os.walk()
What it is and what it does
scandir is a backport of os.scandir() from Python 3.5+, providing a faster alternative to os.walk() and os.listdir() by returning DirEntry objects with cached file type and stat information. Instead of making separate system calls to determine whether each entry is a file or directory, it reuses data already returned by the OS, reducing overhead by roughly 2–20 times depending on platform and filesystem. The package yields results as a generator rather than a list, improving memory efficiency for large directories.
The module is intended for Python 2.7 and 3.4+, though it has been archived and is no longer maintained. On Python 3.5 and later, the built-in os.scandir() is available and should be preferred; this package exists mainly as a compatibility shim for older Python versions that are themselves now out of support.
Use it for:
- Recursively walking large directory trees on Python 2.7 or 3.4 where os.scandir() is unavailable.
- Filtering files by type (directory, symlink, regular file) without extra stat() calls in legacy codebases.
- Iterating very large directories with memory constraints by using a generator instead of loading all names at once.
- Porting code from Python 3.5+ back to older Python versions while maintaining performance.
- Batch file operations (copying, deleting, analyzing) where avoiding redundant stat calls matters.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides faster directory iteration and os.walk() replacement by yielding DirEntry objects with cached file type and stat information, avoiding redundant system calls.
No, unless you are stuck on Python 2.7 or 3.4 and cannot upgrade. The package is abandoned (last release 2019, repository archived), and Python 3.5+ includes os.scandir() in the standard library. If you are on a modern Python version, use os.scandir() directly. If you must support legacy Python, this package works but will receive no updates.
Install
scandir on PyPI
pip
pip install scandiruv
uv add scandirpoetry
poetry add scandirInstalling scandir
Before you install
Medium install friction due to compiled C extension (wheels provided for Python 2.7 and 3.4–3.7 on Windows). Repository is archived and last release was in 2019; this package is effectively superseded by os.scandir() in Python 3.5+.
License in practice
New BSD License (permissive) allows commercial and private use with minimal restrictions, making it safe for most projects.
Quickstart
pip install scandir
try:
from os import scandir
except ImportError:
from scandir import scandir
for entry in scandir('.'):
if entry.is_file():
print(entry.name)
Requires a C compiler on non-Windows platforms to build the extension; prebuilt wheels available for Windows and common CPython versions.
Verify before relying
- Whether the package still builds cleanly on modern Python versions beyond 3.7.
- Performance gains relative to os.scandir() in Python 3.5+ (package may offer no advantage on current Python).
Package facts
| License | New BSD License (permissive) |
| Python support | not specified |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 2,715 days since the last release |
| Last repo commit | (repository archived) |
| First released | |
| Downloads | 2,332,754/month — #3,131 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: scandir-1.10.0-cp27-cp27m-win32.whl; scandir-1.10.0-cp27-cp27m-win_amd64.whl; scandir-1.10.0-cp34-cp34m-win32.whl; scandir-1.10.0-cp34-cp34m-win_amd64.whl; scandir-1.10.0-cp35-cp35m-win32.whl; scandir-1.10.0-cp35-cp35m-win_amd64.whl; scandir-1.10.0-cp36-cp36m-win32.whl; scandir-1.10.0-cp36-cp36m-win_amd64.whl; scandir-1.10.0-cp37-cp37m-win32.whl; scandir-1.10.0-cp37-cp37m-win_amd64.whl
Tags
More Filesystems packages
Watches file system changes and triggers…
permissive · top 1,000 on PyPI
watchdogWatchdog monitors file system events across…
permissive · top 1,000 on PyPI
portalockerPortalocker provides cross-platform file…
permissive · top 1,000 on PyPI
filetypeInfers file type and MIME type by examining…
permissive · top 1,000 on PyPI
pathvalidateSanitize and validate filenames and file paths…
permissive · top 5,000 on PyPI
pathlibProvides object-oriented filesystem path…
permissive · top 5,000 on PyPI
scantreeRecursively scans directories with flexible…
permissive · top 5,000 on PyPI
ignore-pythonProvides fast recursive directory traversal…
unclear · top 15,000 on PyPI
rignoreProvides fast directory traversal with support…
permissive · top 1,000 on PyPI
provide-dirCreates a directory and all its parent…
permissive · top 15,000 on PyPI
trailrunnerWalk filesystem paths while respecting…
permissive · top 5,000 on PyPI
iteratorsWraps Python iterators to add timeout behavior,…
permissive · top 15,000 on PyPI
py-walkFilters filesystem paths using gitignore-style…
permissive · top 5,000 on PyPI
jsonslicerParses JSON streams and large files without…
permissive · top 15,000 on PyPI
cronitercroniter iterates over datetime objects using…
permissive · top 1,000 on PyPI