Skip to content

Active File Resource

ActiveFileResource(client)

Bases: ContentResource

Operations on the currently active (open) file in Obsidian.

Source code in src/aiobsidian/rest/_base.py
def __init__(self, client: ObsidianClient) -> None:
    self._client = client

get(*, content_type=ContentType.MARKDOWN) async

get(
    *, content_type: Literal[ContentType.MARKDOWN] = ...
) -> str
get(
    *, content_type: Literal[ContentType.NOTE_JSON]
) -> NoteJson
get(
    *, content_type: Literal[ContentType.DOCUMENT_MAP]
) -> DocumentMap

Get the content of the active file.

Parameters:

Name Type Description Default
content_type ContentType

Desired response format. Use ContentType.MARKDOWN for raw text, ContentType.NOTE_JSON for structured JSON, or ContentType.DOCUMENT_MAP for headings/blocks.

MARKDOWN

Returns:

Type Description
str | NoteJson | DocumentMap

File content as str, NoteJson, or DocumentMap

str | NoteJson | DocumentMap

depending on the requested content type.

Source code in src/aiobsidian/rest/active.py
async def get(
    self,
    *,
    content_type: ContentType = ContentType.MARKDOWN,
) -> str | NoteJson | DocumentMap:
    """Get the content of the active file.

    Args:
        content_type: Desired response format. Use
            `ContentType.MARKDOWN` for raw text,
            `ContentType.NOTE_JSON` for structured JSON, or
            `ContentType.DOCUMENT_MAP` for headings/blocks.

    Returns:
        File content as `str`, `NoteJson`, or `DocumentMap`
        depending on the requested content type.
    """
    return await self._get_content(self._BASE_URL, content_type)

update(content) async

Replace the entire content of the active file.

Parameters:

Name Type Description Default
content str

New Markdown content for the file.

required
Source code in src/aiobsidian/rest/active.py
async def update(self, content: str) -> None:
    """Replace the entire content of the active file.

    Args:
        content: New Markdown content for the file.
    """
    await self._client.request(
        "PUT",
        self._BASE_URL,
        content=content,
        headers={"Content-Type": ContentType.MARKDOWN},
    )

append(content) async

Append content to the end of the active file.

Parameters:

Name Type Description Default
content str

Markdown content to append.

required
Source code in src/aiobsidian/rest/active.py
async def append(self, content: str) -> None:
    """Append content to the end of the active file.

    Args:
        content: Markdown content to append.
    """
    await self._append_content(self._BASE_URL, content)

patch(content, *, operation, target_type, target, target_delimiter='::') async

Patch a specific section of the active file.

Parameters:

Name Type Description Default
content str

Content to insert or replace.

required
operation PatchOperation

How to apply the content (append, prepend, or replace).

required
target_type TargetType

What to target (heading, block, or frontmatter).

required
target str

The target identifier.

required
target_delimiter str

Delimiter for nested targets.

'::'
Source code in src/aiobsidian/rest/active.py
async def patch(
    self,
    content: str,
    *,
    operation: PatchOperation,
    target_type: TargetType,
    target: str,
    target_delimiter: str = "::",
) -> None:
    """Patch a specific section of the active file.

    Args:
        content: Content to insert or replace.
        operation: How to apply the content (`append`, `prepend`,
            or `replace`).
        target_type: What to target (`heading`, `block`, or
            `frontmatter`).
        target: The target identifier.
        target_delimiter: Delimiter for nested targets.
    """
    await self._patch_content(
        self._BASE_URL,
        content,
        operation=operation,
        target_type=target_type,
        target=target,
        target_delimiter=target_delimiter,
    )

delete() async

Delete the currently active file.

Source code in src/aiobsidian/rest/active.py
async def delete(self) -> None:
    """Delete the currently active file."""
    await self._client.request("DELETE", self._BASE_URL)