Skip to main content

Python bindings for agentdir — virtual filesystem for agent-optimized file exploration

Project description

agentdir

Virtual filesystem for agent-optimized file exploration using CoW reflinks.

agentdir is a Python binding for the agentdir Rust library. It lets you map real directories into a virtual file tree, move and copy entries without touching source files, track source changes, and fork the tree into isolated snapshots via copy-on-write.

  • Version: 0.1.2
  • 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.


Quick Start

from agentdir import Workspace

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

content = ws.read_bytes("/docs/readme.md")
print(content.decode())

ws.mv("/docs/readme.md", "/readme.md")  # source files are untouched

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


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 source file on disk is not touched.

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

Copy a virtual entry. The source 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. "/docs/*.txt", "/src/**/*.py"). 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 source 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("./my-docs", "/docs")
print(f"Mapped {summary['entries_added']} entries")

content = ws.read_bytes("/docs/readme.md")
print(content.decode())

ws.mv("/docs/readme.md", "/readme.md")  # source files untouched

Snapshots with isolated writes

from agentdir import Workspace

ws = Workspace.init("./workspace")
ws.map("./project", "/src")

snap = ws.snapshot("experiment")
snap.write("/src/config.json", b'{"experimental": true}')

# Base workspace is unaffected:
original = ws.read_bytes("/src/config.json")
modified = snap.read_bytes("/src/config.json")

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.3.tar.gz (81.4 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.3-cp39-abi3-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.9+Windows x86-64

agentdir-0.1.3-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.3-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.3-cp39-abi3-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

agentdir-0.1.3-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.3.tar.gz.

File metadata

  • Download URL: agentdir-0.1.3.tar.gz
  • Upload date:
  • Size: 81.4 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.3.tar.gz
Algorithm Hash digest
SHA256 664928aa5ca18f549466d0197e634f130c695aa6fcc7f6ad8d2da48c267314a9
MD5 f3b89a680e36a0f8ee1d97ce7883c025
BLAKE2b-256 5d98537e37168e7ec178be5191f0ed34ce5d0ee933b5af6637aec3d05b9b95d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentdir-0.1.3.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.3-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: agentdir-0.1.3-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.3-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d86e995b94869e8aa753b009bd878e52b82d3d05984cd863413a172d008ec053
MD5 ff6140442b9e86bfa9ef0120e5e29689
BLAKE2b-256 8528d54a3f3b7905cc0d00baa369d4de359774165c772e4d38748883808d3ce3

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentdir-0.1.3-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.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for agentdir-0.1.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f25d56b18696b4ed5fe75b7361716530fc38dafa79a007a92c1f8c96822a1f0a
MD5 c63e498af408850197d9023b9a3fe18f
BLAKE2b-256 caa8cd5d207c8c3f8dd85a5e3bb3a3178e603883d799be8ffd61bf64a2c2318d

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentdir-0.1.3-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.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for agentdir-0.1.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0debebc31bf935643c3bcc7f8ee0c2911c181b818cf43d860861749f25a07a26
MD5 f28bfea264c4a77a7f4b393fe04f4e4a
BLAKE2b-256 6277b4c6c74501e7d13cdaba77ac3215f4430e90aaaffdd93fe7333d0746fe51

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentdir-0.1.3-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.3-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for agentdir-0.1.3-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e44a679dcb4a071511b3e53e854e2e7d0e4f9e81075f7a089970d79231826502
MD5 2d5fac134a93807a010be32a6b9951b9
BLAKE2b-256 4c8e8463c390826d9d7b5729328495eec5aa5f3dead3837bd4292ccbc27d46c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentdir-0.1.3-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.3-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for agentdir-0.1.3-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 159d0f2f6f6374cd4f8b126d0f8749f245dbd123c6366cf1ea8a1c6f88eab39f
MD5 adc7e4f9fe848343da5b17935877c22f
BLAKE2b-256 214a8e0572872982f7598fe437cbb553b40b110cc9226ed80e7c636e42a9adb2

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentdir-0.1.3-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