Skip to content

CLI Tags Resource

CLITagsResource(cli)

Bases: BaseCLIResource

CLI resource for tag 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

get(name) async

Get notes that contain a specific tag.

Parameters:

Name Type Description Default
name str

Tag name (without # prefix).

required

Returns:

Type Description
list[dict[str, Any]]

List of matching note objects.

Source code in src/aiobsidian/cli/tags.py
async def get(self, name: str) -> list[dict[str, Any]]:
    """Get notes that contain a specific tag.

    Args:
        name: Tag name (without ``#`` prefix).

    Returns:
        List of matching note objects.
    """
    output = await self._cli._execute("tag", params={"tagname": name})
    result: list[dict[str, Any]] = json.loads(output)
    return result

rename(old, new) async

Rename a tag across the entire vault.

Parameters:

Name Type Description Default
old str

Current tag name.

required
new str

New tag name.

required
Source code in src/aiobsidian/cli/tags.py
async def rename(self, old: str, new: str) -> None:
    """Rename a tag across the entire vault.

    Args:
        old: Current tag name.
        new: New tag name.
    """
    await self._cli._execute("tags:rename", params={"old": old, "new": new})

list(*, sort=None, path=None, counts=False) async

List all tags in the vault.

Parameters:

Name Type Description Default
sort str | None

Sort order (e.g. "count" to sort by frequency).

None
path str | None

Restrict to tags found under this path.

None
counts bool

If True, include usage counts per tag.

False

Returns:

Type Description
list[dict[str, Any]]

List of tag objects.

Source code in src/aiobsidian/cli/tags.py
async def list(
    self,
    *,
    sort: str | None = None,
    path: str | None = None,
    counts: bool = False,
) -> list[dict[str, Any]]:
    """List all tags in the vault.

    Args:
        sort: Sort order (e.g. ``"count"`` to sort by frequency).
        path: Restrict to tags found under this path.
        counts: If ``True``, include usage counts per tag.

    Returns:
        List of tag objects.
    """
    params: dict[str, str] = {}
    if sort:
        params["sort"] = sort
    if path is not None:
        params["path"] = path
    flags = ["--counts"] if counts else None
    output = await self._cli._execute("tags", params=params or None, flags=flags)
    result: list[dict[str, Any]] = json.loads(output)
    return result