fava.ext

Fava’s extension system.

exception fava.ext.ExtensionConfigError(error, config)
class fava.ext.FavaExtensionBase(ledger, config=None)

Base class for extensions for Fava.

Any extension should inherit from this class. find_extension() will discover all subclasses of this class in the specified modules.

after_delete_entry(entry)

Run after an entry has been deleted.

Return type:

None

after_entry_modified(entry, new_lines)

Run after an entry has been modified.

Return type:

None

after_insert_entry(entry)

Run after an entry has been inserted.

Return type:

None

after_insert_metadata(entry, key, value)

Run after metadata (key: value) was added to an entry.

Return type:

None

after_load_file()

Run after a ledger file has been loaded.

Return type:

None

after_write_source(path, source)

Run after source has been written to path.

Return type:

None

before_request()

Run before each client request.

Return type:

None

config: Any
endpoints: dict[tuple[str, str], Callable[[FavaExtensionBase], Any]]
property extension_dir: Path

Directory to look for templates directory and Javascript code.

has_js_module: bool = False

Whether this extension includes a Javascript module.

property jinja_env: Environment

Jinja env for this extension.

property name: str

Unique name of this extension.

report_title: str | None = None

Name for a HTML report for this extension.

class fava.ext.FavaExtensionError(source: Meta | None, message: str, entry: Directive | None)

Error in one of Fava’s extensions.

exception fava.ext.JinjaLoaderMissingError
fava.ext.extension_endpoint(func_or_endpoint_name=None, methods=None)

Decorator to mark a function as an endpoint.

Can be used as @extension_endpoint or @extension_endpoint(endpoint_name, methods).

When used as @extension_endpoint, the endpoint name is the name of the function and methods is “GET”.

When used as @extension_endpoint(endpoint_name, methods), the given endpoint name and methods are used, but both are optional. If endpoint_name is None, default to the function name, and if methods is None, default to “GET”.

Return type:

Union[Callable[[TypeVar(T, bound= FavaExtensionBase)], Response], Callable[[Callable[[TypeVar(T, bound= FavaExtensionBase)], Response]], Callable[[TypeVar(T, bound= FavaExtensionBase)], Response]]]

fava.ext.find_extensions(base_path, name)

Find extensions in a module.

Parameters:
  • base_path (Path) – The module can be relative to this path.

  • name (str) – The name of the module containing the extensions.

Returns:

tuple[list[type[FavaExtensionBase]], list[FavaExtensionError]] – A tuple (classes, errors) where classes is a list of subclasses of FavaExtensionBase found in name.

fava.ext.auto_commit

Auto-commit hook for Fava.

This mainly serves as an example how Fava’s extension systems, which only really does hooks at the moment, works.

class fava.ext.auto_commit.AutoCommit(ledger, config=None)

Auto-commit hook for Fava.

after_delete_entry(entry)

Commit all changes on after_delete_entry.

Return type:

None

after_entry_modified(entry, _new_lines)

Commit all changes on after_entry_modified.

Return type:

None

after_insert_entry(entry)

Commit all changes on after_insert_entry.

Return type:

None

after_insert_metadata(_entry, _key, _value)

Commit all changes on after_insert_metadata.

Return type:

None

after_write_source(path, _source)

Add changed file to git and commit.

Return type:

None