Skip to main content
   ┌──────────────────────────────────────────────────┐
   │  c o d e c h u — f s                             │
   │   .                                              │
   │   ├── atomic_write()    safe.tmp -> fsync -> mv  │
   │   ├── move_to_trash()   ~/.local/share/Trash/    │
   │   ├── walk()            cancellable + loop-safe  │
   │   └── mountpoint()      /proc/mounts aware       │
   └──────────────────────────────────────────────────┘

Filesystem primitives for tools that must not lose data.

codechu-fs

Stdlib-only filesystem helpers — atomic writes, XDG trash, cancellable walks, mount discovery — extracted from the Disk Cleaner toolchain. Zero third-party dependencies. Python 3.10+.

What it gives you

  • atomic_write — tempfile in the same dir, fsync, then rename. Preserves existing permissions. Either bytes or text (with encoding).
  • move_to_trash — freedesktop XDG Trash Specification compliant. Honors XDG_DATA_HOME, writes a .trashinfo, resolves name collisions.
  • walk — os.walk with three things os.walk is missing: a cancel Event for cooperative shutdown, an on_error callback (no silent swallow), and symlink-loop detection when following links.
  • recursive_size — sum of bytes under a directory, cancellable.
  • mountpoint — the mount that contains a path, parsed from /proc/mounts on Linux with a st_dev fallback elsewhere.
  • is_safe_path — path-traversal guard for user-supplied inputs.
  • temp_dir — context-managed temp directory, auto-removed.

Install

pip install codechu-fs

Quick examples

from pathlib import Path
from threading import Event
from codechu_fs import (
    atomic_write, move_to_trash, walk, recursive_size,
    mountpoint, is_safe_path, temp_dir,
)

# Durable write — never leaves a half-written file even if you crash mid-write.
atomic_write("/etc/myapp/config.json", b'{"k":1}\n')
atomic_write("notes.txt", "hello\n", encoding="utf-8")

# Send a file to the desktop trash (recoverable from the file manager).
trashed = move_to_trash("/tmp/junk.log")
print("now at:", trashed)

# Cancellable walk — stop instantly when the user clicks Cancel.
cancel = Event()
for dirpath, dirnames, filenames in walk("/var/log", cancel=cancel):
    if some_condition():
        cancel.set()

# Total size of a directory tree (skips unreadable files).
print(recursive_size(Path.home() / "Downloads"))

# What partition is this on?
print(mountpoint("/var/log/syslog"))   # → /var, or / on most systems

# Safe extraction of an untrusted filename.
if is_safe_path(user_input, base="/srv/uploads"):
    ...

# Scratch space that always cleans up.
with temp_dir(prefix="myapp-") as scratch:
    (scratch / "work.bin").write_bytes(b"...")

Design

  • Pure stdlib. Zero third-party dependencies. Seven small modules.
  • Defensive. walk never swallows errors silently. atomic_write fsyncs before rename. move_to_trash rolls back its .trashinfo on failure.
  • Cancellable. Every traversal accepts a threading.Event. Long scans on slow disks remain responsive in GUI apps.

Tests

pip install -e ".[dev]"
pytest -q

Documentation

  • API reference — every public symbol, signatures, edge cases
  • Recipes — five idiomatic patterns for CLIs and GUIs

License

MIT — see LICENSE.

Metadata

Release files for codechu-fs 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for codechu-fs 0.1.0
File Size Uploaded
codechu_fs-0.1.0.tar.gz 14.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for codechu-fs 0.1.0
File Interpreter ABI Platform
codechu_fs-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.9 kB

Release files / codechu_fs-0.1.0.tar.gz

Download URL codechu_fs-0.1.0.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
38dec0a05582e72e4f0b6761e759b475e0ec514e64b1225ae11f875c2ef70d9b
BLAKE2b-256 checksum
How to use checksums
710ff6c783bcb929bf0cac486134cb49394fa0db611d3dc85f93bc675100034c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 20, 2026.

Transparency log

Release files / codechu_fs-0.1.0-py3-none-any.whl

Download URL codechu_fs-0.1.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c214540cd87295766bcc6b3c4143845f376fec1c970a885d4812b0d12851af2e
BLAKE2b-256 checksum
How to use checksums
9f7c0dd48f493d0df56c8f56cba63e310f0c1b8b28021a7a00841fc87ef8007f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 20, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page