skillfed

scandir

scandir, a better directory iterator and faster os.walk()

scandir v1.10.0 2.3M downloads/30d#3,131 on PyPI538
Permissive license New BSD License Abandoned released

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 scandir

uv

uv add scandir

poetry

poetry add scandir

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: Implementation :: CPythonTopic :: System :: FilesystemsTopic :: System :: Operating System

Tags

fast directory iterationos.walk replacementdirectory scanning performanceDirEntry objectsefficient os.listdirreduce stat callsfilesystem traversal
filesystemlegacy-pythonperformance

More Filesystems packages