Skip to main content

Minimal Python bindings for dua-cli traversal trees

Project description

dua-py

A minimal Python interface around the Rust traversal engine from dua-cli.

dua represents a traversal as an in-memory StableGraph<EntryData, (), Directed> with TreeIndex node IDs. This package uses PyO3 and maturin to run that traversal, integrate the emitted events into the graph, and return nested Python objects that keep the same tree shape.

Install

pip install dua-py

What gets bundled

dua-py uses the Rust library API from dua-cli; it does not shell out to the dua command-line executable.

When you install a PyPI wheel, the compiled Rust extension includes the dua-cli library code and its Rust dependencies. You do not need to install the standalone dua binary separately.

PyPI wheels are currently built for macOS and Linux. Windows wheels are not published because dua-cli currently requires an unstable Rust feature for its Windows library build.

When pip falls back to the source distribution, the dua-cli source is not vendored into this repository. The build uses Cargo.toml and Cargo.lock, so the machine installing from source needs Rust/Cargo and access to crates.io to fetch and compile the Rust dependencies.

Install for development

python -m venv .venv
source .venv/bin/activate
python -m pip install maturin pytest
maturin develop
pytest

Usage

from pathlib import Path

import dua_py

root = dua_py.walk(Path("."))
print(root.path, root.size, root.entry_count)

for child in root.children:
    print(child.name, child.size)

For multiple traversal roots, use scan():

roots = dua_py.scan(["src", "tests"], apparent_size=True)

API

dua_py.walk(path, **options) -> Entry

Scan a single filesystem path and return one Entry.

dua_py.scan(paths, **options) -> tuple[Entry, ...]

Scan one or more filesystem paths and return the top-level traversal entries.

Options:

  • threads: int | None = None - number of walker threads. None uses the available CPU parallelism.
  • apparent_size: bool = False - use metadata length instead of allocated disk usage.
  • count_hard_links: bool = False - count every hard-link occurrence independently.
  • cross_filesystems: bool = True - allow traversal to cross filesystem boundaries.
  • ignore_dirs: Iterable[path] | None = None - directories to skip.
  • sort: bool = True - sort entries alphabetically while walking and returning children.
  • use_root_path: bool = True - keep the root path as the root entry name.

Entry

Entry is an immutable dataclass:

@dataclass(frozen=True)
class Entry:
    name: str
    path: str
    size: int
    mtime: float
    entry_count: int | None
    metadata_io_error: bool
    is_dir: bool
    children: tuple[Entry, ...]

size is reported in bytes. mtime is seconds since the Unix epoch. For directories, size and entry_count are recursively aggregated by dua.

Project details


Download files

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

Source Distribution

dua_py-0.1.0.tar.gz (23.0 kB view details)

Uploaded Source

Built Distributions

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

dua_py-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (547.0 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

dua_py-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (500.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

dua_py-0.1.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (860.0 kB view details)

Uploaded CPython 3.10+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file dua_py-0.1.0.tar.gz.

File metadata

  • Download URL: dua_py-0.1.0.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dua_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 953b2fbf3b57a149855eabb1431df8e7cb9972f5252d52e458ce56a189cf3a38
MD5 f4911f2a7dbc99701b889ab17b8ae56b
BLAKE2b-256 bed3a094842ebaeaabba5cac81fa7122eb88bc43e0f071765126f55c64ea0bec

See more details on using hashes here.

File details

Details for the file dua_py-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for dua_py-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5711435146121d7d8fcd2bb5de5d6976a568d7c51548fd5e291ed4e9cddc2912
MD5 43e687a30ae84ae6221d92154db8ae3f
BLAKE2b-256 b76204d119e1a7e9e9aba5611bed3b4e0509cd14d32400f4fa3ce41dd58a0b4f

See more details on using hashes here.

File details

Details for the file dua_py-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for dua_py-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 66878800d63d869bfd8c218350391a546e8f5b655a61e1d746df7f646cd4a9e0
MD5 32bbe761a5d62b05c4879dc36a3458e2
BLAKE2b-256 f31f60d6e346dc888ed99961212ef60b6c407707558b2819ff8cb7ff7b2d4cd0

See more details on using hashes here.

File details

Details for the file dua_py-0.1.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for dua_py-0.1.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 fdc7ec70be91ed0817390bb2083129af3d4dac099054144a70aa2c8a2460f052
MD5 8342bcce8600b87b67ba411efc35f33c
BLAKE2b-256 bf05b3afc30927701a92f88ad747f365b71e464256b605d1b228cda75a5d90a4

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