Skip to content

Vault Operations

obsidian_palace.vault.operations

Vault file operations — read, write, list, and path utilities.

All file operations are scoped to the configured vault directory. Path traversal is prevented by validating resolved paths stay within the vault root.

logger = logging.getLogger(__name__) module-attribute

read_note(relative_path: str) -> str async

Read a note's content from the vault.

Parameters:

Name Type Description Default
relative_path str

Path to the note relative to vault root.

required

Returns:

Type Description
str

The note content as a string.

Raises:

Type Description
FileNotFoundError

If the note does not exist.

ValueError

If the path escapes the vault.

write_note(relative_path: str, content: str) -> Path async

Write content to a note in the vault.

Creates parent directories as needed. Obsidian Sync will pick up the change on the next sync cycle.

Parameters:

Name Type Description Default
relative_path str

Path to the note relative to vault root.

required
content str

Markdown content to write.

required

Returns:

Type Description
Path

The absolute path of the written file.

Raises:

Type Description
ValueError

If the path escapes the vault.

list_folders(relative_path: str = '') -> list[str] async

List subdirectories under a vault path.

Parameters:

Name Type Description Default
relative_path str

Subfolder to list (default: vault root).

''

Returns:

Type Description
list[str]

Sorted list of subfolder names.

Raises:

Type Description
ValueError

If the path escapes the vault.

FileNotFoundError

If the path does not exist.

list_notes(relative_path: str = '', extensions: tuple[str, ...] = ('.md',)) -> list[str] async

List note files under a vault path.

Parameters:

Name Type Description Default
relative_path str

Subfolder to list (default: vault root).

''
extensions tuple[str, ...]

File extensions to include.

('.md',)

Returns:

Type Description
list[str]

Sorted list of note filenames.

Raises:

Type Description
ValueError

If the path escapes the vault.