Account: Hierarchical Account Path#

class means.types.Account.Account(root: RootModelRootType = PydanticUndefined)#

A hierarchical account path, stored as a tuple of colon-delimited segments.

I Construction and Templates#

classmethod Account.new(val: str | tuple[str, ...] | Iterable[str]) → Account#

Build an account from a path string, a tuple/iterable of segments, or another account.

Parameters:

val – A colon-delimited path string, segment collection, or Account to copy.

Returns:

The constructed (or copied) account.

classmethod Account.setup(root: Annotated[Path, PathType(path_type=dir)]) → None#

Load the account and template registries from the given data directory.

Idempotent: does nothing if the class has already been set up.

Parameters:

root – The means data directory containing accounts.ledger and parameter files.

classmethod Account.build_template(node: dict[str, Any], parent: Account | None = None) → dict[Account, list[tuple[Pattern, str]]]#

Parse a dictionary tree from YAML into template accounts and their regex pairs.

Each node can contain children nodes and/or leaf nodes, each of which represents a regex/replacement pair. Each leaf is associated with a full account path built by concatenating all of its parents with colon delimiters, such as r:expenses:shopping.

Parameters:
  • node – A dictionary node from a yaml file.

  • parent – The account path built from this node’s parents. Should be left blank when calling on the root node.

Returns:

A mapping of each template account to its regex/replacement pairs.

II Identity and Navigation#

Account.type#

The account type derived from the first path segment.

Account.user#

The user uid in the second path segment, or '' when the account has no user.

Account.uid#

The path segments joined with double underscores, safe for use as an identifier.

Account.validate_acct() → bool#

Check whether the account is registered or is an Unknown placeholder.

Account.ancestors#

This account followed by each of its ancestors, from deepest to shallowest.

Account.endswith(other: Account | str) → bool#

Check whether this account’s path ends with the other account’s segments.

Account.startswith(other: Account | str) → bool#

Check whether this account’s path starts with the other account’s segments.

Account.with_user(user: str) → Account#

Return a copy of this account with its user segment set to the given uid.

Parameters:

user – The user uid to insert (or substitute) as the second segment.