fava¶
Fava - A web interface for Beancount.
fava._babel¶
Custom Babel extractor for Svelte files.
fava._ctx_globals_class¶
Specify types for the flask application context.
- class fava._ctx_globals_class.Context¶
The context values - this is used for flask.g.
- property conv: Conversion¶
Conversion to apply (parsed).
- extension: FavaExtensionBase | None¶
The current extension, if this is an extension endpoint
- property filtered: FilteredLedger¶
The filtered ledger.
- ledger: FavaLedger¶
The ledger
fava._structs¶
msgspec Structs used in serialisation.
- class fava._structs.Balance(account: str, amount: _Amount, diff_amount: _Amount | None = None, tolerance: Decimal | None = None, *, date: date, meta: dict[str, str | bool | int | _Amount], entry_hash: str = '')¶
-
- amount: _Amount¶
- class fava._structs.Close(account: str, *, date: date, meta: dict[str, str | bool | int | _Amount], entry_hash: str = '')¶
- class fava._structs.Commodity(currency: str, *, date: date, meta: dict[str, str | bool | int | _Amount], entry_hash: str = '')¶
- class fava._structs.Custom(type: str, values: list[str | bool | date | Decimal | _Amount], *, date: date, meta: dict[str, str | bool | int | _Amount], entry_hash: str = '')¶
- class fava._structs.Document(account: str, filename: str, tags: frozenset[str] | None = None, links: frozenset[str] | None = None, *, date: date, meta: dict[str, str | bool | int | _Amount], entry_hash: str = '')¶
- class fava._structs.EntryStruct(*, date: date, meta: dict[str, str | bool | int | _Amount], entry_hash: str = '')¶
msgspec Struct representations of entries.
- class fava._structs.Event(type: str, description: str, *, date: date, meta: dict[str, str | bool | int | _Amount], entry_hash: str = '')¶
- class fava._structs.Note(account: str, comment: str, tags: frozenset[str] | None = None, links: frozenset[str] | None = None, *, date: date, meta: dict[str, str | bool | int | _Amount], entry_hash: str = '')¶
- class fava._structs.Open(account: str, currencies: list[str] | None, booking: Booking | None = None, *, date: date, meta: dict[str, str | bool | int | _Amount], entry_hash: str = '')¶
- class fava._structs.Pad(account: str, source_account: str, *, date: date, meta: dict[str, str | bool | int | _Amount], entry_hash: str = '')¶
- class fava._structs.Posting(*, account: str, amount: str = '', flag: str = '', meta: dict[str, str | bool | int | _Amount] | None = None)¶
- class fava._structs.Price(currency: str, amount: _Amount, *, date: date, meta: dict[str, str | bool | int | _Amount], entry_hash: str = '')¶
- amount: _Amount¶
- class fava._structs.Query(name: str, query_string: str, *, date: date, meta: dict[str, str | bool | int | _Amount], entry_hash: str = '')¶
fava.application¶
Fava’s main WSGI application.
you can use create_app to create a Fava WSGI app for a given list of files. To start a simple server:
from fava.application import create_app
app = create_app(['/path/to/file.beancount'])
app.run('localhost', 5000)
- fava.application.create_app(files, *, load=False, incognito=False, read_only=False, poll_watcher=False)¶
Create a Fava Flask application.
- Parameters:
- Return type:
- fava.application.static_url(filename)¶
Return a static url with an mtime query string for cache busting.
- Return type:
fava.cli¶
The command-line interface for Fava.
- exception fava.cli.AddressInUse(port)¶
- exception fava.cli.NoFileSpecifiedError¶
- exception fava.cli.NonAbsolutePathError(path)¶
fava.context¶
Specify types for the flask application context.
fava.helpers¶
Exceptions and module base class.
- class fava.helpers.BeancountError(source: Meta | None, message: str, entry: Directive | None = None)¶
NamedTuple base for a Beancount-style error.
- exception fava.helpers.FavaAPIError(message=None)¶
Fava’s base exception class.
fava.internal_api¶
Internal API.
This is used to pre-process some data that is used in the templates, allowing this part of the functionality to be tested and allowing some end-to-end tests for the frontend data validation.
- class fava.internal_api.BalancesChart(label: str, data: Sequence[DateAndBalance], type: Literal['balances'] = 'balances')¶
Data for a balances chart.
- class fava.internal_api.BarChart(label: str, data: Sequence[DateAndBalanceWithBudget], type: Literal['bar'] = 'bar')¶
Data for a bar chart.
- class fava.internal_api.ChartApi¶
Functions to generate chart data.
- static account_balance(account_name)¶
Generate data for an account balances chart.
- Return type:
- static hierarchy(account_name, *, label=None)¶
Generate data for an account hierarchy chart.
- Return type:
- static interval_totals(interval, account_name, label=None, *, invert=False)¶
Generate data for an account per interval chart.
- Return type:
- static net_worth()¶
Generate data for net worth chart.
- Return type:
- class fava.internal_api.HierarchyChart(label: str, data: SerialisedTreeNode, type: Literal['hierarchy'] = 'hierarchy')¶
Data for a hierarchy chart.
- data: SerialisedTreeNode¶
- class fava.internal_api.LedgerData(accounts: Sequence[str], account_details: AccountDict, base_url: str, currencies: Sequence[str], currency_names: dict[str, str], errors: Sequence[SerialisedError], fava_options: FavaOptions, incognito: bool, have_excel: bool, links: Sequence[str], options: dict[str, str | Sequence[str]], payees: Sequence[str], precisions: dict[str, int], tags: Sequence[str], years: Sequence[str], user_queries: Sequence[object], upcoming_events_count: int, extensions: Sequence[ExtensionDetails], sidebar_links: Sequence[tuple[str, str]], other_ledgers: Sequence[tuple[str, str]])¶
This is used as report-independent data in the frontend.
- account_details: AccountDict¶
- errors: Sequence[SerialisedError]¶
- extensions: Sequence[ExtensionDetails]¶
- fava_options: FavaOptions¶
- class fava.internal_api.SerialisedError(type: str, source: Mapping[str, str | int | bool | Decimal | date | Amount] | None, message: str)¶
A Beancount error, as passed to the frontend.
- static from_beancount_error(err)¶
Get a serialisable error from a Beancount error.
- Return type:
- fava.internal_api.get_errors()¶
Serialise errors (do not pass entry as that might fail serialisation.
- Return type:
- fava.internal_api.get_ledger_data()¶
Get the report-independent ledger data.
- Return type:
fava.json_api¶
JSON API.
This module contains the url endpoints of the JSON API that is used by the web interface for asynchronous functionality.
- class fava.json_api.AddDocumentForm(folder: str, account: str, hash: str = '')¶
Required form fields when adding a document.
- exception fava.json_api.DocumentDirectoryMissingError(message=None)¶
You need to set a documents folder.
- status = 422¶
- exception fava.json_api.FavaJSONAPIError(message=None)¶
An error with a HTTPStatus.
- abstract property status: HTTPStatus¶
HTTP status that should be used for the response.
- exception fava.json_api.FileDoesNotExistError(filename)¶
The given file does not exist.
- status = 404¶
- class fava.json_api.HelpPage(html: str, pages: Sequence[tuple[str, str]])¶
A rendered help page and the list of all help pages.
- exception fava.json_api.InvalidJsonRequestError¶
Invalid JSON body.
- class fava.json_api.JournalPage(page: int, total_pages: int, journal: str)¶
A rendered journal page.
- exception fava.json_api.NotAValidDocumentOrImportFileError(filename)¶
Not valid document or import file.
- status = 400¶
- class fava.json_api.Options(fava_options: Mapping[str, str], beancount_options: Mapping[str, str])¶
Fava and Beancount options as strings.
- class fava.json_api.SourceFile(file_path: str, sha256sum: str, source: str)¶
Source slice for an entry.
- class fava.json_api.Statistics(all_balance_directives: str, balances: Mapping[str, SimpleCounterInventory], entries_by_type: Mapping[str, int])¶
Data for the statistics report.
- balances: Mapping[str, SimpleCounterInventory]¶
- exception fava.json_api.TargetPathAlreadyExistsError(path)¶
The given path already exists.
- status = 409¶
- class fava.json_api.TreeReport(date_range: DateRange | None, charts: Sequence[BalancesChart | BarChart | HierarchyChart], trees: Sequence[SerialisedTreeNode])¶
Data for the tree reports.
- charts: Sequence[BalancesChart | BarChart | HierarchyChart]¶
- trees: Sequence[SerialisedTreeNode]¶
- exception fava.json_api.UploadedFileIsMissingFilenameError(message=None)¶
Uploaded file is missing filename.
- status = 400¶
- fava.json_api.api_endpoint(func)¶
Register an API endpoint.
The part of the function name up to the first underscore determines the accepted HTTP method. For GET and DELETE endpoints, the function parameters are converted from the URL query string; for PUT endpoints, they are decoded from the JSON request body. Both use a msgspec Struct generated from the function’s parameters for the typed validation.
- fava.json_api.build_json_body_decoder(func)¶
Build a msgspec-typed decoder for the JSON body of an endpoint.
- fava.json_api.build_query_string_decoder(func)¶
Build a msgspec-typed decoder for an endpoint’s query string.
- fava.json_api.delete_source_slice(entry_hash, sha256sum)¶
Delete an entry source slice.
- Return type:
- fava.json_api.get_account_report(a='', r='')¶
Get the data for the account report.
- Return type:
AccountReportJournal|AccountReportTree
- fava.json_api.get_balance_sheet()¶
Get the data for the balance sheet.
- Return type:
- fava.json_api.get_commodities()¶
Get the prices for all commodity pairs.
- Return type:
Sequence[CommodityPairWithPrices]
- fava.json_api.get_context(entry_hash)¶
Entry context.
- Return type:
Context
- fava.json_api.get_extract(filename, importer)¶
Extract entries using the ingest framework.
- fava.json_api.get_help(page_slug)¶
Get one of Fava’s help pages, rendered to HTML.
- Return type:
- fava.json_api.get_imports()¶
Get a list of the importable files.
- Return type:
- fava.json_api.get_income_statement()¶
Get the data for the income statement.
- Return type:
- fava.json_api.get_journal_page(page, order)¶
Get the HTML contents for a Journal page.
- Return type:
- fava.json_api.get_narration_transaction(narration)¶
Last transaction for the given narration.
- Return type:
- fava.json_api.get_options()¶
Get all options, rendered to strings for displaying in the frontend.
- Return type:
- fava.json_api.get_payee_accounts(payee)¶
Rank accounts for the given payee.
- fava.json_api.get_payee_transaction(payee)¶
Last transaction for the given payee.
- Return type:
- fava.json_api.get_query(query_string)¶
Run a Beancount query.
- Return type:
- fava.json_api.get_source(filename='')¶
Load one of the source files.
- Return type:
- fava.json_api.get_source_slice(entry_hash)¶
Entry slice.
- Return type:
- fava.json_api.get_statistics()¶
Get the data for the statistics report.
- Return type:
- fava.json_api.get_trial_balance()¶
Get the data for the trial balance.
- Return type:
- fava.json_api.put_attach_document(filename, entry_hash)¶
Attach a document to an entry.
- Return type:
- fava.json_api.put_source(file_path, source, sha256sum)¶
Write one of the source files and return the updated sha256sum.
- Return type:
- fava.json_api.put_source_slice(entry_hash, source, sha256sum)¶
Write an entry source slice and return the updated sha256sum.
- Return type:
- fava.json_api.validate_file()¶
Validate the form request contains a file with filename.
fava.serialisation¶
(De)serialisation of entries.
When adding entries, these are saved via the JSON API - using the functionality of this module to obtain the appropriate data structures from beancount.core.data. Similarly, for the full entry completion, a JSON representation of the entry is provided.
This is not intended to work well enough for full roundtrips yet.
- exception fava.serialisation.InvalidAmountError(amount)¶
Invalid amount.
- fava.serialisation.deserialise(entry)¶
Convert an entry received from the frontend to a Beancount entry.
- Return type:
- fava.serialisation.serialise(o)¶
- fava.serialisation.serialise(o)
- fava.serialisation.serialise(o)
- fava.serialisation.serialise(o)
- fava.serialisation.serialise(o)
- fava.serialisation.serialise(o)
- fava.serialisation.serialise(o)
- fava.serialisation.serialise(o)
- fava.serialisation.serialise(o)
- fava.serialisation.serialise(o)
- fava.serialisation.serialise(o)
- fava.serialisation.serialise(o)
- fava.serialisation.serialise(o)
- fava.serialisation.serialise(o)
- fava.serialisation.serialise(o)
Map a value so that it can be serialised to JSON.
- Return type:
fava.template_filters¶
Template filters for Fava.
All functions in this module will be automatically added as template filters.
- fava.template_filters.format_currency(value, currency=None)¶
Format a value using the derived precision for a specified currency.
- Return type:
- fava.template_filters.meta_items(meta)¶
Remove keys from a dictionary.