Skip to main content

A fast file tree scanner written in Rust

Project description

scandir-rs

The Python module is called scandir_rs and installable via pip. It is an alternative to os.walk() and os.scandir() with more features and higher speed. On Linux it is 3 - 11 times faster and on Windows 6 - 70 time faster (see benchmarks).
It releases the GIL and the scanning is done in a background thread. With different methods intermediate results can be read.

If you are just interested in directory statistics you can use the Count.

scandir_rs contains following classes:

  • Count for determining statistics of a directory.
  • Walk for getting names of directory entries.
  • Scandir for getting detailed stats of directory entries.

For the API see:

Installation

For building this wheel from source you need the tool maturin.

Install maturin:

cargo install maturin

IMPORTANT: In order to build this project at least Rust version 1.61 is needed!

Build wheel:

Change to directory pyscandir.

Build wheel (on Linux):

maturin build --release --strip

Build wheel on Windows:

maturin build --release --strip --no-sdist

maturin will build the wheels for all Python versions installed on your system.

Alternatively you can use the build script build_wheels.py. The precondition to run this script is to have pyenv installed. The script can build the wheel for specific Python versions or for all Python versions installed by pyenv. In addition it runs pytest after successfull creation of each wheel.

python build_wheels.py

By default the script will build the wheel for the current Python interpreter. If you want to build the wheel for specific Python version(s) by providing the argument --versions.

python build_wheels.py --versions 3.11.8,3.12.2

To build the wheel for all installed Python versions:

python build_wheels.py --versions *

Instruction how to install pyenv can be found on github.

Examples

Get statistics of a directory:

from scandir_rs import Count, ReturnType

print(Count("/usr", return_type=ReturnType.Ext).collect())

The collect method releases the GIL. So other Python threads can run in parallel.

The same, but asynchronously in background using a class instance:

from scandir_rs import Count, ReturnType

instance = Count("/usr", return_type=ReturnType.Ext)
instance.start()  # Start scanning the directory in background
...
values = instance.results()  # Returns the current statistics. Can be read at any time
...
if instance.busy():  # Check if the task is still running.
...
instance.stop()  # If you want to cancel the task
...
instance.join()  # Wait for the instance to finish.

and with a context manager:

import time

from scandir_rs import Count, ReturnType

with Count("/usr", return_type=ReturnType.Ext) as instance:
    while instance.busy():
        statistics = instance.results()
        # Do something
        time.sleep(0.01)
    print(instance.results())

os.walk() example:

from scandir_rs import Walk

for root, dirs, files in Walk("/usr"):
    # Do something

with extended data:

from scandir_rs import Walk, ReturnType

for root, dirs, files, symlinks, other, errors in Walk("/usr", return_type=ReturnType.Ext):
    # Do something

os.scandir() example:

from scandir_rs import Scandir, ReturnType

for path, entry in Scandir("~/workspace", return_type=ReturnType.Ext):
    # entry is a custom DirEntry object

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

scandir_rs-2.9.7-cp314-cp314-manylinux_2_34_x86_64.whl (495.4 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

scandir_rs-2.9.7-cp313-cp313-manylinux_2_34_x86_64.whl (495.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

scandir_rs-2.9.7-cp312-cp312-manylinux_2_34_x86_64.whl (495.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

scandir_rs-2.9.7-cp311-cp311-manylinux_2_34_x86_64.whl (495.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

scandir_rs-2.9.7-cp310-cp310-manylinux_2_34_x86_64.whl (495.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

File details

Details for the file scandir_rs-2.9.7-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for scandir_rs-2.9.7-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7512e25f0098a8110dba17e446472a2164f3702dce071ca3cd3533c5cb8751c0
MD5 a15f71e16e728b4645d8bd8b4a03ef9f
BLAKE2b-256 bac616479570085aa1f93e195ed5dd68abf500e30ef65d17c292670a5f9fc938

See more details on using hashes here.

File details

Details for the file scandir_rs-2.9.7-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for scandir_rs-2.9.7-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 eb6878fabc1cf4c6585bc72fc1c01c40fd211e495801539363d44eabc29d99c4
MD5 d6db53535028f02074a29c84cb5d123a
BLAKE2b-256 ad3a725cf9bb7f2700df32d12d569a9f0ba2726b7b448f3355ecc44347c4e994

See more details on using hashes here.

File details

Details for the file scandir_rs-2.9.7-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for scandir_rs-2.9.7-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4883fcc2179c7b34c110c2440fbe11857dbd1f4352f1ce8c2cc00af167ac79c4
MD5 097bda2d4413b39bd877103ba7898845
BLAKE2b-256 82305dde5d75a89d6a0ab9c6d424519b4c2370865632cc62f970adcd1360e6be

See more details on using hashes here.

File details

Details for the file scandir_rs-2.9.7-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for scandir_rs-2.9.7-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 aa2b1be402e45a8da13d2aa59f2c388aab74488e35dcfb514c27817804b604e5
MD5 fe1546d6e6135233aaf44440d18ef0f6
BLAKE2b-256 4310995e7065e23ee2a940d3e64d2132a266410f295182d238d69c90ee0c2062

See more details on using hashes here.

File details

Details for the file scandir_rs-2.9.7-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for scandir_rs-2.9.7-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 cb08e5307c7e5c903b59993a45b0469cf601e64d470fda74e992ee0e3f4cdcf6
MD5 ff7befa1c06e1ec2ea44d03fc1575a3f
BLAKE2b-256 dc88e35d15ccb91d86374561ddf1cf05e36a3c32719feed8d1ba88e079e4b31c

See more details on using hashes here.

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