Skip to main content

Python bindings for agentdir — virtual file tree infrastructure for agent-ready file layouts

Project description

agentdir

Virtual filesystem for agent-optimized exploration of general-purpose files using CoW reflinks.

agentdir is a Python binding for the agentdir Rust library. It lets you map real directories of documents, media, datasets, generated artifacts, plain text, binaries, or any other OS-visible files into a virtual file tree, move and copy entries without touching the originals, track original-file changes, and fork the tree into isolated snapshots via copy-on-write.

  • Version: 0.1.6
  • License: MIT
  • Python: >= 3.9
  • Built with: PyO3 + maturin (native Rust extension, abi3 wheels)

Installation

pip install agentdir

No extra dependencies. The package ships pre-built abi3 wheels for Linux, macOS, and Windows.

Installation only installs the binding. After mapping original files, call Workspace.refresh() whenever the original file tree may have changed. The Python binding exposes reconciliation through refresh() and refresh_with_hash_verification(); it does not start the CLI watch loop for you.


Quick Start

from agentdir import Workspace

ws = Workspace.init("./workspace")
summary = ws.map("./team-files", "/files")
print(f"Mapped {summary['entries_added']} entries")

content = ws.read_bytes("/files/q1-report.txt")
print(content.decode())

ws.mv("/files/q1-report.txt", "/reports/q1-report.txt")  # original files are untouched

# Reconcile source changes before an agent/session depends on the view.
sync = ws.refresh()
print(sync)

All methods are synchronous. There is no async API. Internally the library runs a Tokio runtime, but the Python surface is fully blocking.

If you also install the CLI, long-running workflows can run agentdir -w ./workspace watch --interval 60 in a separate process. The watcher combines filesystem events with periodic full rescans; Python applications should otherwise call refresh() on their own schedule or at session boundaries.


API Reference

Import

from agentdir import Workspace, SnapshotWorkspace

Workspace

Static methods

Workspace.init(path: str, strategy: str = "reflink") -> Workspace

Initialize a new workspace at path. The strategy controls how files are materialized:

Value Behavior
"reflink" CoW reflink, falls back to byte-copy if unsupported (default)
"symlink" Symbolic links
"virtual" Metadata-only, no materialization
Workspace.open(path: str) -> Workspace

Open an existing workspace. Raises FileNotFoundError if the workspace does not exist at path.


Instance methods

map(source: str, mount: str) -> dict[str, int]

Map a source directory into the virtual tree at mount. Returns a summary dict:

{
    "entries_added": int,
    "reflinked":     int,
    "copied":        int,
    "symlinked":     int,
    "dirs_created":  int,
    "errors":        int,
}
unmap(mount: str) -> dict[str, int]

Remove the mapping at mount and clean up its entries. Returns:

{"entries_removed": int}
mv(from_path: str, to_path: str) -> None

Move a virtual entry. The original file on disk is not touched.

cp(from_path: str, to_path: str) -> None

Copy a virtual entry. The original file on disk is not touched.

mkdir(path: str) -> None

Create a virtual directory.

rmdir(path: str, recursive: bool) -> None

Remove a virtual directory. Pass recursive=True to remove non-empty directories.

rename(path: str, new_name: str) -> None

Rename the last path component of a virtual entry. new_name is a bare name, not a full path.

exists(path: str) -> bool

Return True if the virtual path exists.

stat(path: str) -> dict[str, object]

Return metadata for a virtual path:

{
    "virtual_path":  str,
    "source_path":   str,
    "size_bytes":    int,
    "mtime_ns":      int,
    "entry_type":    str,   # "File" or "Directory"
    "materialized":  bool,
}
read_bytes(path: str) -> bytes

Read the raw bytes of a file at the given virtual path.

refresh() -> dict[str, int]

Detect changes in source directories and apply them to the virtual tree. Returns:

{
    "added":     int,
    "refreshed": int,
    "removed":   int,
    "errors":    int,
}
refresh_with_hash_verification(verify_hashes: bool = False) -> dict[str, int]

Same as refresh(), with an optional SHA-256 pass. When verify_hashes=True, files whose mtime and size are unchanged are additionally verified by content hash to catch silent modifications. Returns the same shape as refresh().

status() -> dict[str, object]

Return workspace-level metadata:

{
    "total_entries":           int,
    "source_roots":            int,
    "materialized_root":       str,
    "last_updated_epoch_secs": int,
}
export_mapping(reverse: bool = False, relative_to: str | None = None) -> dict[str, str]

Export the source-to-virtual path mapping as a plain dict. Pass reverse=True to get virtual-to-source instead. Pass relative_to to relativize source paths against a base directory.

map_batch(mappings: list[tuple[str, str]]) -> dict[str, object]

Map multiple files in one call. Each tuple is (source_path, mount_point). Note: batch map accepts files only, not directories. Returns:

{
    "entries_added": int,
    "reflinked":     int,
    "copied":        int,
    "symlinked":     int,
    "dirs_created":  int,
}
rglob(pattern: str) -> list[str]

Match virtual paths against a glob pattern. Supports * and ** wildcards (e.g. "/files/*.pdf", "/media/**/*.png"). Returns a list of matching virtual paths.

list_snapshots() -> list[str]

Return the names of all snapshots attached to this workspace.

snapshot(name: str) -> SnapshotWorkspace

Create a named CoW snapshot of the current virtual tree. The snapshot starts as a fork of the workspace and accepts isolated writes.

open_snapshot(name: str) -> SnapshotWorkspace

Open an existing named snapshot.

destroy_snapshot(name: str) -> None

Destroy a named snapshot and remove its files from disk.


SnapshotWorkspace

A CoW fork of a Workspace. Writes to a snapshot are isolated and do not affect the base workspace or any original files.

exists(path: str) -> bool

Return True if the virtual path exists in this snapshot.

stat(path: str) -> dict[str, object]

Return metadata for a virtual path. Same shape as Workspace.stat().

read_bytes(path: str) -> bytes

Read the raw bytes of a file in this snapshot.

write(path: str, content: bytes) -> None

Write content to a file in this snapshot. The write is copy-on-write and does not affect the base workspace.

export_mapping(reverse: bool = False, relative_to: str | None = None) -> dict[str, str]

Export the path mapping for this snapshot. Same semantics as Workspace.export_mapping().

destroy() -> None

Destroy this snapshot and remove all its files from disk.


Examples

Map a directory and read files

from agentdir import Workspace

ws = Workspace.init("./workspace")
summary = ws.map("./team-files", "/files")
print(f"Mapped {summary['entries_added']} entries")

content = ws.read_bytes("/files/q1-report.txt")
print(content.decode())

ws.mv("/files/q1-report.txt", "/reports/q1-report.txt")  # original files untouched

Snapshots with isolated writes

from agentdir import Workspace

ws = Workspace.init("./workspace")
ws.map("./team-files", "/files")

snap = ws.snapshot("experiment")
snap.write("/files/q1-report.txt", b"snapshot-only draft")

# Base workspace is unaffected:
original = ws.read_bytes("/files/q1-report.txt")
modified = snap.read_bytes("/files/q1-report.txt")

snap.destroy()

License

MIT. See LICENSE for details.

For the CLI and Rust library, see the main repository: https://github.com/NomaDamas/agentdir

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

agentdir-0.1.6.tar.gz (87.5 kB view details)

Uploaded Source

Built Distributions

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

agentdir-0.1.6-cp39-abi3-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.9+Windows x86-64

agentdir-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

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

agentdir-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

agentdir-0.1.6-cp39-abi3-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

agentdir-0.1.6-cp39-abi3-macosx_10_12_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file agentdir-0.1.6.tar.gz.

File metadata

  • Download URL: agentdir-0.1.6.tar.gz
  • Upload date:
  • Size: 87.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for agentdir-0.1.6.tar.gz
Algorithm Hash digest
SHA256 43436fa69170923861bae1f9ac5a4e871f6fae6d4b79afb84faf2edc965e85af
MD5 704974723e506f13703bd02e4ede230c
BLAKE2b-256 e784c25f45a8b40a500543d7501a00742710cb7866097d052cad9703e6b20df6

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentdir-0.1.6.tar.gz:

Publisher: release-python.yml on NomaDamas/agentdir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agentdir-0.1.6-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: agentdir-0.1.6-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for agentdir-0.1.6-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1519657d9b1580010e99f95e463c23e157a2e9d2d5708d750e2c2793e18a1d96
MD5 ec52a51875617f4ab4f9d2648366f895
BLAKE2b-256 f9ae962c7378d5106cee6debcd01895c4dea6d5a2f088132adfeab0b86bdb9bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentdir-0.1.6-cp39-abi3-win_amd64.whl:

Publisher: release-python.yml on NomaDamas/agentdir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agentdir-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for agentdir-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e0afd6c02918942e78042224a1142a749389695b78bde68f463b48325311673f
MD5 64c95d9a0d34a958f10085b79e565dde
BLAKE2b-256 e7c32ff023d9272ad1ab4e5bac890a581b2673273c68fecdf59fbb1efa7bf1a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentdir-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-python.yml on NomaDamas/agentdir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agentdir-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for agentdir-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 467943cb309c1937edab63401c15d5f64299c5908fa0fbffb8fb1ba849c4fdcf
MD5 6c5e989b9f7292a47e064b4b68a6e60f
BLAKE2b-256 cfe73dc4badaa314250f6cafeb9bec571cd08697adcf4392d0a6a838302855dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentdir-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release-python.yml on NomaDamas/agentdir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agentdir-0.1.6-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for agentdir-0.1.6-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2cef27cd188f1372c88ea285af698a6e0cc492aa2e9c92f2c77b2186ced470d7
MD5 b5279360706c5864e482faf52bb9f9a2
BLAKE2b-256 7c2394409062505bae66ef4330293a97fcf4dd31f9f73d1f393f8920798de40a

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentdir-0.1.6-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release-python.yml on NomaDamas/agentdir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agentdir-0.1.6-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for agentdir-0.1.6-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1799022b978f501259c189c329ae5c34a3523cfbc857ff865d0bdccfd66001dd
MD5 696971ebc96346f23042e11da4ad7028
BLAKE2b-256 019adddf288001486c278b31bfc3f5727dca2ec2247f886ae647e6848846a25d

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentdir-0.1.6-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release-python.yml on NomaDamas/agentdir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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