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

Uploaded CPython 3.9+Windows x86-64

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

Uploaded CPython 3.9+macOS 11.0+ ARM64

agentdir-0.1.5-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.5.tar.gz.

File metadata

  • Download URL: agentdir-0.1.5.tar.gz
  • Upload date:
  • Size: 81.7 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.5.tar.gz
Algorithm Hash digest
SHA256 32e501bd2ea94bc4e19b1a2a96a41f051cf9498bc46d9a4ab14ce2682dda7584
MD5 c935c0b4721e6bfe8584404bc607220e
BLAKE2b-256 76b6032b1d985fee06ef1feffc972c7ab286f8638093e5a145caa8f16e0e25a0

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: agentdir-0.1.5-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.5-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4cb77b10d40f2027710b2490ccd99e154942b85eee573395ffe19ba4e10b2f21
MD5 f4078fa7a19ae285e1558e73bc21763a
BLAKE2b-256 bdab0f7bbc5b8ea31395203b64f318fa5471233a0a21ff64f9983aa31c83a86a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for agentdir-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b296a487384c391801d5ec70dc80bf272b77636e2291d6465542aaaa284f0e79
MD5 3a70c6b6b4ad97982a6b39b02cd73bb5
BLAKE2b-256 e341503992710394ce09f0126d7d9db90a388c212b71be188edd405193719b23

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for agentdir-0.1.5-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5418260c53c141cb9b8406e51e9fdda77ae0c8e75769f308f07ed75348e99a37
MD5 1a2aca6ccb36e5cf0cbac6cc1e446104
BLAKE2b-256 378f3625dda77a13ccf5698f0d5b98048e88fd9406b9aa2c63691d9c995138ba

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for agentdir-0.1.5-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3159ac20b96bb4a17ac669809092706ea6a12bf34519929e856bdee9cd7a2af7
MD5 33bcf01f1d04fda0541c20a1a90f8226
BLAKE2b-256 2ff9a79293440c3eb2277fd8b8669b1b413e0e6cbb81fd8e6cafff699f12ea38

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for agentdir-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 978ed1dd8edf3050f7793a1c6eec1182669dcbed56d842462da5f828bbe5d8c6
MD5 07bcd00d72a09bbb2e679ce4b58e49b3
BLAKE2b-256 a22d9e546a3050d49c23450a013c2cf58f04928bbd6aedf856a6de954f99c056

See more details on using hashes here.

Provenance

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