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

Uploaded CPython 3.9+Windows x86-64

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

Uploaded CPython 3.9+macOS 11.0+ ARM64

agentdir-0.1.4-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.4.tar.gz.

File metadata

  • Download URL: agentdir-0.1.4.tar.gz
  • Upload date:
  • Size: 81.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.4.tar.gz
Algorithm Hash digest
SHA256 7ef7373f904217172450666ef0be6b4a70fcd18ebe6fc8c47f0935e959b803ff
MD5 e8248c3c7882d343d4b9bbd760655c83
BLAKE2b-256 ba10dc9b1bb8ff71451ece5eb7c5ad570affba2074b36d56694d52551fcd64ba

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: agentdir-0.1.4-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.4-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b5935061f071b19dffdecb025e96bef7daec04f0d1761a6f3c05ac54e4c4847a
MD5 e3bacb867b500a97b490d7a500191a13
BLAKE2b-256 ebcce6f5acf97dd98c34c4b2707372835a8fe802485ca6546256f60b5ccc1bca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for agentdir-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 35c685f74f77e4e84a4796eb5e1e61c2aef608282529f36545c57bce47a5f78c
MD5 acbdc904bf4f603817dc7bd16695e566
BLAKE2b-256 c03c50edfb78d76318d91b382a0e3188324937343a4643838e74fdc7214a1487

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for agentdir-0.1.4-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3d28c54e8f8093338ab3efd9e29befcb61773b8b235bce3f13c1844e758b8116
MD5 4c0cd5c99f36a152abde48528d8be615
BLAKE2b-256 371d918e56823b681d87dd5ca9b3345fddba0d3c5a46ac3577e828403e6c5a1e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for agentdir-0.1.4-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b0082fd739988ebbc8c5c482c55b0f8076ab031ee3dddc88256679fd654d9fd1
MD5 6e55f652ec5d5671312a92c1afc3d5fd
BLAKE2b-256 24e0c65eba6033c08f2e3d48f3cbfc054bcf3503ccc7e9042ca8384ca5cf3b29

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for agentdir-0.1.4-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a420cbbef6342dd00feb27319a6e8724c15ba7b84c43f428effe73e9ebf87b15
MD5 f25b66c2198535beda43bd43887101f1
BLAKE2b-256 e91d32969a78d34c232eb1feb3e1c22ad84d56682d264faad000d6b278358bc0

See more details on using hashes here.

Provenance

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