Skip to content

CLI Vault Resource

CLIVaultResource(cli)

Bases: BaseCLIResource

CLI resource for vault file operations.

Attributes:

Name Type Description
_cli

Reference to the parent ObsidianCLI instance.

Source code in src/aiobsidian/cli/_base.py
def __init__(self, cli: ObsidianCLI) -> None:
    self._cli = cli

open(path) async

Open a file in the Obsidian UI.

Parameters:

Name Type Description Default
path str

Path to the file relative to the vault root.

required
Source code in src/aiobsidian/cli/vault.py
async def open(self, path: str) -> None:
    """Open a file in the Obsidian UI.

    Args:
        path: Path to the file relative to the vault root.
    """
    await self._cli._execute("open", params={"path": path})

read(path) async

Read the content of a vault file.

Parameters:

Name Type Description Default
path str

Path to the file relative to the vault root.

required

Returns:

Type Description
str

File content as a string.

Source code in src/aiobsidian/cli/vault.py
async def read(self, path: str) -> str:
    """Read the content of a vault file.

    Args:
        path: Path to the file relative to the vault root.

    Returns:
        File content as a string.
    """
    return await self._cli._execute("read", params={"path": path})

create(path, content, *, name=None, template=None, overwrite=False, silent=False) async

Create a new file in the vault.

Parameters:

Name Type Description Default
path str

Path for the new file relative to the vault root.

required
content str

File content.

required
name str | None

Display name for the note.

None
template str | None

Template to use for the new file.

None
overwrite bool

If True, overwrite an existing file.

False
silent bool

If True, suppress output.

False
Source code in src/aiobsidian/cli/vault.py
async def create(
    self,
    path: str,
    content: str,
    *,
    name: str | None = None,
    template: str | None = None,
    overwrite: bool = False,
    silent: bool = False,
) -> None:
    """Create a new file in the vault.

    Args:
        path: Path for the new file relative to the vault root.
        content: File content.
        name: Display name for the note.
        template: Template to use for the new file.
        overwrite: If ``True``, overwrite an existing file.
        silent: If ``True``, suppress output.
    """
    params: dict[str, str] = {"path": path, "content": content}
    if name is not None:
        params["name"] = name
    if template is not None:
        params["template"] = template
    flags: list[str] = []
    if overwrite:
        flags.append("--overwrite")
    if silent:
        flags.append("--silent")
    await self._cli._execute("create", params=params, flags=flags or None)

append(path, content, *, inline=False) async

Append content to a vault file.

Parameters:

Name Type Description Default
path str

Path to the file relative to the vault root.

required
content str

Content to append.

required
inline bool

If True, append inline without a newline separator.

False
Source code in src/aiobsidian/cli/vault.py
async def append(self, path: str, content: str, *, inline: bool = False) -> None:
    """Append content to a vault file.

    Args:
        path: Path to the file relative to the vault root.
        content: Content to append.
        inline: If ``True``, append inline without a newline separator.
    """
    flags = ["--inline"] if inline else None
    await self._cli._execute(
        "append", params={"path": path, "content": content}, flags=flags
    )

prepend(path, content) async

Prepend content to a vault file.

Parameters:

Name Type Description Default
path str

Path to the file relative to the vault root.

required
content str

Content to prepend.

required
Source code in src/aiobsidian/cli/vault.py
async def prepend(self, path: str, content: str) -> None:
    """Prepend content to a vault file.

    Args:
        path: Path to the file relative to the vault root.
        content: Content to prepend.
    """
    await self._cli._execute("prepend", params={"path": path, "content": content})

move(path, to) async

Move a vault file to a new location.

Parameters:

Name Type Description Default
path str

Current path relative to the vault root.

required
to str

Destination path relative to the vault root.

required
Source code in src/aiobsidian/cli/vault.py
async def move(self, path: str, to: str) -> None:
    """Move a vault file to a new location.

    Args:
        path: Current path relative to the vault root.
        to: Destination path relative to the vault root.
    """
    await self._cli._execute("move", params={"path": path, "to": to})

rename(path, new_name) async

Rename a vault file.

Parameters:

Name Type Description Default
path str

Current path relative to the vault root.

required
new_name str

New file name (without directory prefix).

required
Source code in src/aiobsidian/cli/vault.py
async def rename(self, path: str, new_name: str) -> None:
    """Rename a vault file.

    Args:
        path: Current path relative to the vault root.
        new_name: New file name (without directory prefix).
    """
    await self._cli._execute("rename", params={"path": path, "new-name": new_name})

delete(path, *, permanent=False) async

Delete a vault file.

Parameters:

Name Type Description Default
path str

Path to the file relative to the vault root.

required
permanent bool

If True, permanently delete instead of moving to trash.

False
Source code in src/aiobsidian/cli/vault.py
async def delete(self, path: str, *, permanent: bool = False) -> None:
    """Delete a vault file.

    Args:
        path: Path to the file relative to the vault root.
        permanent: If ``True``, permanently delete instead of moving
            to trash.
    """
    flags = ["--permanent"] if permanent else None
    await self._cli._execute("delete", params={"path": path}, flags=flags)

info() async

Get vault information.

Returns:

Type Description
dict[str, Any]

Vault details including name and configuration.

Source code in src/aiobsidian/cli/vault.py
async def info(self) -> dict[str, Any]:
    """Get vault information.

    Returns:
        Vault details including name and configuration.
    """
    output = await self._cli._execute("vault")
    result: dict[str, Any] = json.loads(output)
    return result

file_info(path) async

Get information about a file.

Parameters:

Name Type Description Default
path str

Path to the file relative to the vault root.

required

Returns:

Type Description
dict[str, Any]

File metadata.

Source code in src/aiobsidian/cli/vault.py
async def file_info(self, path: str) -> dict[str, Any]:
    """Get information about a file.

    Args:
        path: Path to the file relative to the vault root.

    Returns:
        File metadata.
    """
    output = await self._cli._execute("file", params={"path": path})
    result: dict[str, Any] = json.loads(output)
    return result

folder_info(path) async

Get information about a folder.

Parameters:

Name Type Description Default
path str

Path to the folder relative to the vault root.

required

Returns:

Type Description
dict[str, Any]

Folder metadata.

Source code in src/aiobsidian/cli/vault.py
async def folder_info(self, path: str) -> dict[str, Any]:
    """Get information about a folder.

    Args:
        path: Path to the folder relative to the vault root.

    Returns:
        Folder metadata.
    """
    output = await self._cli._execute("folder", params={"path": path})
    result: dict[str, Any] = json.loads(output)
    return result

folders(path='') async

List folders in the vault.

Parameters:

Name Type Description Default
path str

Directory path relative to the vault root. Empty string lists all folders.

''

Returns:

Type Description
list[str]

List of folder paths.

Source code in src/aiobsidian/cli/vault.py
async def folders(self, path: str = "") -> list[str]:
    """List folders in the vault.

    Args:
        path: Directory path relative to the vault root.
              Empty string lists all folders.

    Returns:
        List of folder paths.
    """
    params = {"path": path} if path else None
    output = await self._cli._execute("folders", params=params)
    result: list[str] = json.loads(output)
    return result

wordcount(path) async

Get word and character count for a file.

Parameters:

Name Type Description Default
path str

Path to the file relative to the vault root.

required

Returns:

Type Description
dict[str, Any]

Word count statistics.

Source code in src/aiobsidian/cli/vault.py
async def wordcount(self, path: str) -> dict[str, Any]:
    """Get word and character count for a file.

    Args:
        path: Path to the file relative to the vault root.

    Returns:
        Word count statistics.
    """
    output = await self._cli._execute("wordcount", params={"file": path})
    result: dict[str, Any] = json.loads(output)
    return result

list(path='', *, ext=None, folder=None) async

List files in the vault.

Parameters:

Name Type Description Default
path str

Directory path relative to the vault root. Empty string lists all files.

''
ext str | None

Filter by file extension (e.g. "md").

None
folder str | None

Filter by folder path.

None

Returns:

Type Description
list[str]

List of file paths.

Source code in src/aiobsidian/cli/vault.py
async def list(
    self,
    path: str = "",
    *,
    ext: str | None = None,
    folder: str | None = None,
) -> list[str]:
    """List files in the vault.

    Args:
        path: Directory path relative to the vault root.
              Empty string lists all files.
        ext: Filter by file extension (e.g. ``"md"``).
        folder: Filter by folder path.

    Returns:
        List of file paths.
    """
    params: dict[str, str] = {}
    if path:
        params["path"] = path
    if ext is not None:
        params["ext"] = ext
    if folder is not None:
        params["folder"] = folder
    output = await self._cli._execute("files", params=params or None)
    result: list[str] = json.loads(output)
    return result