fava.core¶
This module provides the data required by Fava’s reports.
- exception fava.core.EntryNotFoundForHashError(entry_hash)¶
Entry not found for hash.
- class fava.core.FavaLedger(path, *, poll_watcher=False)¶
Create an interface for a Beancount ledger.
- Parameters:
path (
str
) – Path to the main Beancount file.
- account_journal(filtered, account_name, conversion, *, with_children)¶
Journal for an account.
- Parameters:
filtered (
FilteredLedger
) – The currently filtered ledger.account_name (
str
) – An account name.conversion (
str
|Conversion
) – The conversion to use.with_children (
bool
) – Whether to include postings of subaccounts of the account.
- Yields:
Tuples of
(entry, change, balance)
.- Return type:
Iterable
[tuple
[Directive
,SimpleCounterInventory
,SimpleCounterInventory
]]
- accounts¶
A
AccountDict
module - details about the accounts.
-
all_entries_by_type:
EntriesByType
¶ Dict of list of all (unfiltered) entries by type.
- attributes¶
An
AttributesModule
instance.
- beancount_file_path¶
The path to the main Beancount file.
- budgets¶
A
BudgetModule
instance.
- changed()¶
Check if the file needs to be reloaded.
- Returns:
bool
– True if a change in one of the included files or a change in a document folder was detected and the file has been reloaded.
- charts¶
A
ChartModule
instance.
- commodities¶
A
CommoditiesModule
instance.
- commodity_pairs()¶
List pairs of commodities.
- context(entry_hash)¶
Context for an entry.
- Parameters:
entry_hash (
str
) – Hash of entry.- Returns:
tuple
[Directive
,Mapping
[str
,Sequence
[str
]] |None
,Mapping
[str
,Sequence
[str
]] |None
,str
,str
] – A tuple(entry, before, after, source_slice, sha256sum)
of the (unique) entry with the givenentry_hash
. If the entry is a Balance or Transaction thenbefore
andafter
contain the balances before and after the entry of the affected accounts.
- property errors: Sequence[BeancountError]¶
The errors that the Beancount loading plus Fava module errors.
- extensions¶
A
ExtensionModule
instance.
-
fava_options:
FavaOptions
¶ A dict with all of Fava’s option values.
-
fava_options_errors:
Sequence
[BeancountError
]¶ A list of all errors from parsing the custom options.
- file¶
A
FileModule
instance.
- format_decimal¶
A
DecimalFormatModule
instance.
- get_entry(entry_hash)¶
Find an entry.
- Parameters:
entry_hash (
str
) – Hash of the entry.- Returns:
Directive
– The entry with the given hash.- Raises:
EntryNotFoundForHashError – If there is no entry for the given hash.
- get_filtered¶
- static group_entries_by_type()¶
Group entries by type.
- Parameters:
- Returns:
EntriesByType
– A namedtuple containing the grouped lists of entries.
- ingest¶
A
IngestModule
instance.
- interval_balances(filtered, interval, account_name, *, accumulate=False)¶
Balances by interval.
- Parameters:
filtered (
FilteredLedger
) – The currently filtered ledger.interval (
Interval
) – An interval.account_name (
str
) – An account name.accumulate (
bool
) – A boolean,True
if the balances for an interval should include all entries up to the end of the interval.
- Returns:
tuple
[Sequence
[Tree
],Sequence
[DateRange
]] – A pair of a list of Tree instances and the intervals.
-
load_errors:
Sequence
[BeancountError
]¶ A list of all errors reported by Beancount.
-
options:
BeancountOptions
¶ The Beancount options map.
- paths_to_watch()¶
Get paths to included files and document directories.
-
prices:
FavaPriceMap
¶ The price map.
- query_shell¶
A
QueryShell
instance.
- statement_path(entry_hash, metadata_key)¶
Get the path for a statement found in the specified entry.
The entry that we look up should contain a path to a document (absolute or relative to the filename of the entry) or just its basename. We go through all documents and match on the full path or if one of the documents with a matching account has a matching file basename.
- Parameters:
- Returns:
str
– The filename of the matching document entry.- Raises:
StatementMetadataInvalidError – If the metadata at the given key is invalid.
StatementNotFoundError – If no matching document is found.
- watcher¶
- class fava.core.FilteredLedger(ledger, *, account=None, filter=None, time=None)¶
Filtered Beancount ledger.
- account_is_closed(account_name)¶
Check if the account is closed.
- entries¶
- interval_ranges(interval)¶
Yield date ranges corresponding to interval boundaries.
- ledger¶
- exception fava.core.StatementMetadataInvalidError(key)¶
Statement metadata not found or invalid.
- exception fava.core.StatementNotFoundError¶
Statement not found.
fava.core.accounts¶
Account close date and metadata.
- class fava.core.accounts.AccountData(close_date=None, meta=<factory>, uptodate_status=None, balance_string=None, last_entry=None)¶
Holds information about an account.
- class fava.core.accounts.AccountDict(ledger)¶
Account info dictionary.
- EMPTY = AccountData(close_date=None, meta={}, uptodate_status=None, balance_string=None, last_entry=None)¶
- setdefault(key, _=None)¶
Get the account of the given name, insert one if it is missing.
- Return type:
- class fava.core.accounts.LastEntry(date, entry_hash)¶
Date and hash of the last entry for an account.
- fava.core.accounts.balance_string(tree_node)¶
Balance directive for the given account for today.
- Return type:
- fava.core.accounts.uptodate_status(txn_postings)¶
Status of the last balance or transaction.
- Parameters:
txn_postings (
Sequence
[Directive
|TransactionPosting
]) – The TransactionPosting for the account.- Returns:
Optional
[Literal
['green'
,'yellow'
,'red'
]] – A status string for the last balance or transaction of the account.’green’: A balance check that passed.
’red’: A balance check that failed.
’yellow’: Not a balance check.
fava.core.attributes¶
Attributes for auto-completion.
fava.core.budgets¶
Parsing and computing budgets.
- class fava.core.budgets.Budget(account: str, date_start: datetime.date, period: Interval, number: Decimal, currency: str)¶
A budget entry.
- fava.core.budgets.BudgetDict¶
A map of account names to lists of budget entries.
- class fava.core.budgets.BudgetError(source: Meta | None, message: str, entry: Directive | None)¶
Error with a budget.
- class fava.core.budgets.BudgetModule(ledger)¶
Parses budget entries.
- calculate(account, begin_date, end_date)¶
Calculate the budget for an account in an interval.
- calculate_children(account, begin_date, end_date)¶
Calculate the budget for an account including its children.
- fava.core.budgets.calculate_budget(budgets, account, date_from, date_to)¶
Calculate budget for an account.
- fava.core.budgets.calculate_budget_children(budgets, account, date_from, date_to)¶
Calculate budget for an account including budgets of its children.
- fava.core.budgets.parse_budgets(custom_entries)¶
Parse budget directives from custom entries.
- Parameters:
custom_entries (
Sequence
[Custom
]) – the Custom entries to parse budgets from.- Returns:
tuple
[dict
[str
,list
[Budget
]],Sequence
[BudgetError
]] – A dict of accounts to lists of budgets.
Example
2015-04-09 custom “budget” Expenses:Books “monthly” 20.00 EUR
fava.core.charts¶
Provide data suitable for Fava’s charts.
- class fava.core.charts.ChartModule(ledger)¶
Return data for the various charts in Fava.
- hierarchy(filtered, account_name, conversion, begin=None, end=None)¶
Render an account tree.
- Return type:
- interval_totals(filtered, interval, accounts, conversion, *, invert=False)¶
Render totals for account (or accounts) in the intervals.
- Parameters:
filtered (
FilteredLedger
) – The filtered ledger.interval (
Interval
) – An interval.accounts (
str
|tuple
[str
,...
]) – A single account (str) or a tuple of accounts.conversion (
str
|Conversion
) – The conversion to use.invert (
bool
) – invert all numbers.
- Yields:
The balances and budgets for the intervals.
- Return type:
- linechart(filtered, account_name, conversion)¶
Get the balance of an account as a line chart.
- Parameters:
filtered (
FilteredLedger
) – The filtered ledger.account_name (
str
) – A string.conversion (
str
|Conversion
) – The conversion to use.
- Yields:
Dicts for all dates on which the balance of the given account has changed containing the balance (in units) of the account at that date.
- Return type:
- net_worth(filtered, interval, conversion)¶
Compute net worth.
- Parameters:
filtered (
FilteredLedger
) – The filtered ledger.interval (
Interval
) – A string for the interval.conversion (
str
|Conversion
) – The conversion to use.
- Yields:
Dicts for all ends of the given interval containing the net worth (Assets + Liabilities) separately converted to all operating currencies.
- Return type:
- class fava.core.charts.DateAndBalance(date, balance)¶
Balance at a date.
-
balance:
SimpleCounterInventory
¶
-
balance:
- class fava.core.charts.DateAndBalanceWithBudget(date, balance, account_balances, budgets)¶
Balance at a date with a budget.
-
account_balances:
Mapping
[str
,SimpleCounterInventory
]¶
-
balance:
SimpleCounterInventory
¶
-
account_balances:
fava.core.commodities¶
Attributes for auto-completion.
fava.core.conversion¶
Commodity conversion helpers for Fava.
All functions in this module will be automatically added as template filters.
- fava.core.conversion.AT_COST = <fava.core.conversion._AtCostConversion object>¶
Convert position to its total cost.
- fava.core.conversion.AT_VALUE = <fava.core.conversion._AtValueConversion object>¶
Convert position to its market value.
- class fava.core.conversion.Conversion¶
A conversion.
- abstract apply(inventory, prices, date=None)¶
Apply the conversion to an inventory.
- Return type:
- fava.core.conversion.UNITS = <fava.core.conversion._UnitsConversion object>¶
Convert position to its units.
- fava.core.conversion.conversion_from_str(value)¶
Parse a conversion string.
- Return type:
- fava.core.conversion.convert_position(pos, target_currency, prices, date=None)¶
Get the value of a Position in a particular currency.
- Parameters:
pos (
Position
) – A Position.target_currency (
str
) – The target currency to convert to.prices (
FavaPriceMap
) – A FavaPriceMapdate (
date
|None
) – A datetime.date instance to evaluate the value at, or None.
- Returns:
Amount
– An Amount, with value converted or if the conversion failed just the cost value (or the units if the position has no cost).
- fava.core.conversion.cost_or_value(inventory, conversion, prices, date=None)¶
Get the cost or value of an inventory.
- Return type:
- fava.core.conversion.get_market_value(pos, prices, date=None)¶
Get the market value of a Position.
This differs from the convert.get_value function in Beancount by returning the cost value if no price can be found.
- Parameters:
pos (
Position
) – A Position.prices (
FavaPriceMap
) – A FavaPriceMapdate (
date
|None
) – A datetime.date instance to evaluate the value at, or None.
- Returns:
Amount
– An Amount, with value converted or if the conversion failed just the cost value (or the units if the position has no cost).
- fava.core.conversion.simple_units(inventory)¶
Get the units of an inventory.
- Return type:
- fava.core.conversion.units(inventory)¶
Get the units of an inventory.
- Return type:
fava.core.documents¶
Document path related helpers.
- exception fava.core.documents.NotADocumentsFolderError(folder)¶
Not a documents folder.
- exception fava.core.documents.NotAValidAccountError(account)¶
Not a valid account.
- fava.core.documents.filepath_in_document_folder(documents_folder, account, filename, ledger)¶
File path for a document in the folder for an account.
- Parameters:
documents_folder (
str
) – The documents folder.account (
str
) – The account to choose the subfolder for.filename (
str
) – The filename of the document.ledger (
FavaLedger
) – The FavaLedger.
- Returns:
Path
– The path that the document should be saved at.
- fava.core.documents.is_document_or_import_file(filename, ledger)¶
Check whether the filename is a document or in an import directory.
- Parameters:
filename (
str
) – The filename to check.ledger (
FavaLedger
) – The FavaLedger.
- Returns:
bool
– Whether this is one of the documents or a path in an import dir.
fava.core.extensions¶
Fava extensions.
- class fava.core.extensions.ExtensionDetails(name, report_title, has_js_module)¶
The information about an extension that is needed for the frontend.
- class fava.core.extensions.ExtensionModule(ledger)¶
Fava extensions.
- property extension_details: Sequence[ExtensionDetails]¶
Extension information to provide to the Frontend.
- get_extension(name)¶
Get the extension with the given name.
- Return type:
fava.core.fava_options¶
Fava’s options.
Options for Fava can be specified through Custom entries in the Beancount file. This module contains a list of possible options, the defaults and the code for parsing the options.
- class fava.core.fava_options.FavaOptions(account_journal_include_children=True, auto_reload=False, collapse_pattern=<factory>, conversion_currencies=(), currency_column=61, default_file=None, default_page='income_statement/', fiscal_year_end=FiscalYearEnd(month=12, day=31), import_config=None, import_dirs=(), indent=2, insert_entry=<factory>, invert_income_liabilities_equity=False, language=None, locale=None, show_accounts_with_zero_balance=True, show_accounts_with_zero_transactions=True, show_closed_accounts=False, sidebar_show_queries=5, unrealized='Unrealized', upcoming_events=7, uptodate_indicator_grey_lookback_days=60, use_external_editor=False)¶
Options for Fava that can be set in the Beancount file.
-
fiscal_year_end:
FiscalYearEnd
= FiscalYearEnd(month=12, day=31)¶
-
insert_entry:
Sequence
[InsertEntryOption
]¶
-
fiscal_year_end:
- class fava.core.fava_options.InsertEntryOption(date, re, filename, lineno)¶
Insert option.
An option that determines where entries for matching accounts should be inserted.
- exception fava.core.fava_options.InvalidFiscalYearEndOptionError(value)¶
- exception fava.core.fava_options.MissingOptionError¶
- exception fava.core.fava_options.NotARegularExpressionError(value)¶
- exception fava.core.fava_options.NotAStringOptionError(key)¶
- class fava.core.fava_options.OptionError(source: Meta | None, message: str, entry: Directive | None)¶
An error for one the Fava options.
- exception fava.core.fava_options.UnknownLocaleOptionError(value)¶
- exception fava.core.fava_options.UnknownOptionError(key)¶
- exception fava.core.fava_options.UnsupportedLanguageOptionError(value)¶
- fava.core.fava_options.parse_option_custom_entry(entry, options)¶
Parse a single custom fava-option entry and set option accordingly.
- Return type:
- fava.core.fava_options.parse_options(custom_entries)¶
Parse custom entries for Fava options.
The format for option entries is the following:
2016-04-01 custom "fava-option" "[name]" "[value]"
- Parameters:
custom_entries (
Sequence
[Custom
]) – A list of Custom entries.- Returns:
tuple
[FavaOptions
,list
[OptionError
]] – A tuple (options, errors) where options is a dictionary of all options to values, and errors contains possible parsing errors.
fava.core.file¶
Reading/writing Beancount files.
- exception fava.core.file.ExternallyChangedError(path)¶
The file changed externally.
- class fava.core.file.FileModule(ledger)¶
Functions related to reading/writing to Beancount files.
- delete_entry_slice(entry_hash, sha256sum)¶
Delete slice of the source file for an entry.
- Parameters:
- Raises:
FavaAPIError – If the entry is not found or the file changed.
- Return type:
- get_source(path)¶
Get source files.
- Parameters:
path (
Path
) – The path of the file.- Returns:
tuple
[str
,str
] – A string with the file contents and the sha256sum of the file.- Raises:
NonSourceFileError – If the file is not one of the source files.
InvalidUnicodeError – If the file contains invalid unicode.
- insert_entries(entries)¶
Insert entries.
- insert_metadata(entry_hash, basekey, value)¶
Insert metadata into a file at lineno.
Also, prevent duplicate keys.
- render_entries(entries)¶
Return entries in Beancount format.
Only renders
Balance
andTransaction
.
- save_entry_slice(entry_hash, source_slice, sha256sum)¶
Save slice of the source file for an entry.
- Parameters:
- Returns:
str
– The sha256sum of the new lines of the entry.- Raises:
FavaAPIError – If the entry is not found or the file changed.
- set_source(path, source, sha256sum)¶
Write to source file.
- Parameters:
- Returns:
str
– The sha256sum of the updated file.- Raises:
NonSourceFileError – If the file is not one of the source files.
InvalidUnicodeError – If the file contains invalid unicode.
ExternallyChangedError – If the file was changed externally.
- exception fava.core.file.InvalidUnicodeError(reason)¶
The source file contains invalid unicode.
- exception fava.core.file.NonSourceFileError(path)¶
Trying to read a non-source file.
- fava.core.file.delete_entry_slice(entry, sha256sum)¶
Delete slice of the source file for an entry.
- Parameters:
- Raises:
ExternallyChangedError – If the file was changed externally.
- Return type:
- fava.core.file.find_entry_lines(lines, lineno)¶
Lines of entry starting at lineno.
- fava.core.file.find_insert_position(entry, insert_options, default_filename)¶
Find insert position for an entry.
- fava.core.file.get_entry_slice(entry)¶
Get slice of the source file for an entry.
- fava.core.file.insert_entry(entry, default_filename, insert_options, currency_column, indent)¶
Insert an entry.
- Parameters:
- Returns:
tuple
[Path
,Sequence
[InsertEntryOption
]] – A changed path and list of updated insert options.
- fava.core.file.insert_metadata_in_file(path, lineno, indent, key, value)¶
Insert the specified metadata in the file below lineno.
Takes the whitespace in front of the line that lineno into account.
- Return type:
- fava.core.file.save_entry_slice(entry, source_slice, sha256sum)¶
Save slice of the source file for an entry.
- Parameters:
- Returns:
str
– The sha256sum of the new lines of the entry.- Raises:
ExternallyChangedError – If the file was changed externally.
fava.core.filters¶
Entry filters.
- class fava.core.filters.AccountFilter(value)¶
Filter by account.
The filter string can either be a regular expression or a parent account.
- class fava.core.filters.AdvancedFilter(value)¶
Filter by tags and links and keys.
- class fava.core.filters.EntryFilter¶
Filters a list of entries.
- exception fava.core.filters.FilterError(filter_type, message)¶
Filter exception.
- exception fava.core.filters.FilterIllegalCharError(char)¶
Filter illegal char error.
- exception fava.core.filters.FilterParseError¶
Filter parse error.
- class fava.core.filters.FilterSyntaxLexer¶
Lexer for Fava’s filter syntax.
- RULES = (('LINK', '\\^[A-Za-z0-9\\-_/.]+'), ('TAG', '\\#[A-Za-z0-9\\-_/.]+'), ('ALL', 'all\\('), ('ANY', 'any\\('), ('KEY', '[a-z][a-zA-Z0-9\\-_]+(?=\\s*(:|=|>=|<=|<|>))'), ('EQ_OP', ':'), ('CMP_OP', '(=|>=|<=|<|>)'), ('NUMBER', '\\d*\\.?\\d+'), ('STRING', '\\w[-\\w]*|"[^"]*"|\'[^\']*\''))¶
- lex(data)¶
A generator yielding all tokens in a given line.
- regex = re.compile('(?P<LINK>\\^[A-Za-z0-9\\-_/.]+)|(?P<TAG>\\#[A-Za-z0-9\\-_/.]+)|(?P<ALL>all\\()|(?P<ANY>any\\()|(?P<KEY>[a-z][a-zA-Z0-9\\-_]+(?=\\s*(:|=|>=|<=|<|>)))|(?P<EQ_OP>:)|(?P<CMP_OP>(=|>=|<=|<|>))|(?P<NUMBER>)¶
- tokens = ('ANY', 'ALL', 'CMP_OP', 'EQ_OP', 'KEY', 'LINK', 'NUMBER', 'STRING', 'TAG')¶
- class fava.core.filters.FilterSyntaxParser¶
-
- precedence = (('left', 'AND'), ('right', 'UMINUS'))¶
- tokens = ('ANY', 'ALL', 'CMP_OP', 'EQ_OP', 'KEY', 'LINK', 'NUMBER', 'STRING', 'TAG')¶
- class fava.core.filters.MatchAmount(op, value)¶
Matches an amount.
- exception fava.core.filters.TimeFilterParseError(value)¶
Time filter parse error.
fava.core.group_entries¶
Entries grouped by type.
- class fava.core.group_entries.EntriesByType(Balance: Sequence[abc.Balance], Close: Sequence[abc.Close], Commodity: Sequence[abc.Commodity], Custom: Sequence[abc.Custom], Document: Sequence[abc.Document], Event: Sequence[abc.Event], Note: Sequence[abc.Note], Open: Sequence[abc.Open], Pad: Sequence[abc.Pad], Price: Sequence[abc.Price], Query: Sequence[abc.Query], Transaction: Sequence[abc.Transaction])¶
Entries grouped by type.
- class fava.core.group_entries.TransactionPosting(transaction: abc.Transaction, posting: abc.Posting)¶
Pair of a transaction and a posting.
- fava.core.group_entries.group_entries_by_account(entries)¶
Group entries by account.
- fava.core.group_entries.group_entries_by_type(entries)¶
Group entries by type.
- Parameters:
- Returns:
EntriesByType
– A namedtuple containing the grouped lists of entries.
fava.core.ingest¶
Ingest helper functions.
- class fava.core.ingest.FileImportInfo(importer_name, account, date, name)¶
Info about one file/importer combination.
- class fava.core.ingest.FileImporters(name, basename, importers)¶
Importers for a file.
-
importers:
list
[FileImportInfo
]¶
-
importers:
- exception fava.core.ingest.ImportConfigLoadError(message)¶
Error on loading the import config.
- exception fava.core.ingest.ImporterExtractError¶
Error calling extract for importer.
- exception fava.core.ingest.ImporterMethodCallError¶
Error calling one of the importer methods.
- class fava.core.ingest.IngestError(source: Meta | None, message: str, entry: Directive | None)¶
An error with one of the importers.
- class fava.core.ingest.IngestModule(ledger)¶
Exposes ingest functionality.
- extract(filename, importer_name)¶
Extract entries from filename with the specified importer.
- import_data()¶
Identify files and importers that can be imported.
- Returns:
list
[FileImporters
] – A list ofFileImportInfo
.
- exception fava.core.ingest.MissingImporterConfigError¶
Missing import-config option.
- exception fava.core.ingest.MissingImporterDirsError¶
You need to set at least one imports-dir.
- fava.core.ingest.extract_from_file(importer, path, existing_entries)¶
Import entries from a document.
- fava.core.ingest.file_import_info(path, importer)¶
Generate info about a file with an importer.
- Return type:
- fava.core.ingest.filepath_in_primary_imports_folder(filename, ledger)¶
File path for a document to upload to the primary import folder.
- Parameters:
filename (
str
) – The filename of the document.ledger (
FavaLedger
) – The FavaLedger.
- Returns:
Path
– The path that the document should be saved at.
- fava.core.ingest.find_imports(config, directory)¶
Pair files and matching importers.
- Yields:
For each file in directory, a pair of its filename and the matching importers.
- Return type:
- fava.core.ingest.get_cached_file(path)¶
Get a cached FileMemo.
This checks the file’s mtime before getting it from the Cache. In addition to using the beangulp cache.
- Return type:
- fava.core.ingest.load_import_config(module_path)¶
Load the given import config and extract importers and hooks.
fava.core.inventory¶
Alternative implementation of Beancount’s Inventory.
- class fava.core.inventory.CounterInventory¶
A lightweight inventory.
This is intended as a faster alternative to Beancount’s Inventory class. Due to not using a list, for inventories with a lot of different positions, inserting is much faster.
The keys should be tuples
(currency, cost)
.- add_inventory(counter)¶
Add another
CounterInventory
.- Return type:
- reduce(reducer, *args, **_kwargs)¶
Reduce inventory.
Note that this returns a simple
CounterInventory
with just currencies as keys.- Return type:
fava.core.misc¶
Some miscellaneous reports.
- class fava.core.misc.FavaError(source: Meta | None, message: str, entry: Directive | None)¶
Generic Fava-specific error.
- class fava.core.misc.FavaMisc(ledger)¶
Provides access to some miscellaneous reports.
- fava.core.misc.sidebar_links(custom_entries)¶
Parse custom entries for links.
They have the following format:
2016-04-01 custom “fava-sidebar-link” “2014” “/income_statement/?time=2014”
- fava.core.misc.upcoming_events(events, max_delta)¶
Parse entries for upcoming events.
fava.core.module_base¶
Base class for the “modules” of FavaLedger.
fava.core.number¶
Formatting numbers.
- class fava.core.number.DecimalFormatModule(ledger)¶
Formatting numbers.
fava.core.query¶
Query result types.
- class fava.core.query.AmountColumn(name, dtype='Amount')¶
An amount query column.
- class fava.core.query.BaseColumn(name, dtype)¶
A query column.
- class fava.core.query.DecimalColumn(name, dtype='Decimal')¶
A Decimal query column.
- class fava.core.query.InventoryColumn(name, dtype='Inventory')¶
A str query column.
- static serialise(val)¶
Serialise an inventory.
- Return type:
- class fava.core.query.ObjectColumn(name, dtype='object')¶
An object query column.
- class fava.core.query.PositionColumn(name, dtype='Position')¶
A Position query column.
- class fava.core.query.QueryResultTable(types, rows, t='table')¶
Table query result.
-
types:
list
[BaseColumn
]¶
-
types:
- class fava.core.query.QueryResultText(contents, t='string')¶
Text query result.
fava.core.query_shell¶
For using the Beancount shell from Fava.
- class fava.core.query_shell.FavaBQLShell(ledger)¶
A light wrapper around Beancount’s shell.
- on_Select(statement)¶
Extract data from a query on the postings.
The general form of a SELECT statement loosely follows SQL syntax, with some mild and idiomatic extensions: :rtype:
Cursor
SELECT [DISTINCT] [<targets>|*] [FROM <from_expr> [OPEN ON <date>] [CLOSE [ON <date>]] [CLEAR]] [WHERE <where_expr>] [GROUP BY <groups>] [ORDER BY <groups> [ASC|DESC]] [LIMIT num]
Where:
- targets: A list of desired output attributes from the postings, and
expressions on them. Some of the attributes of the parent transaction directive are made available in this context as well. Simple functions (that return a single value per row) and aggregation functions (that return a single value per group) are available. For the complete list of supported columns and functions, see help on “targets”. You can also provide a wildcard here, which will select a reasonable default set of columns for rendering a journal.
- from_expr: A logical expression that matches on the attributes of
the directives (not postings). This allows you to select a subset of transactions, so the accounting equation is respected for balance reports. For the complete list of supported columns and functions, see help on “from”.
- where_expr: A logical expression that matches on the attributes of
postings. The available columns are similar to those in the targets clause, without the aggregation functions.
- OPEN clause: replace all the transactions before the given date by
summarizing entries and transfer Income and Expenses balances to Equity.
CLOSE clause: Remove all the transactions after the given date and
CLEAR: Transfer final Income and Expenses balances to Equity.
- exception fava.core.query_shell.FavaShellError(message)¶
An error in the Fava BQL shell, will be turned into a string.
- exception fava.core.query_shell.NonExportableQueryError¶
Only queries that return a table can be printed to a file.
- exception fava.core.query_shell.QueryCompilationError(err)¶
Query compilation error.
- exception fava.core.query_shell.QueryNotFoundError(name)¶
Query ‘{name}’ not found.
- exception fava.core.query_shell.QueryParseError(err)¶
Query parse error.
- class fava.core.query_shell.QueryShell(ledger)¶
A Fava module to run BQL queries.
- execute_query_serialised(entries, query)¶
Run a query and returns its serialised result.
- Parameters:
- Returns:
QueryResultTable
|QueryResultText
– Either a table or a text result (depending on the query).- Raises:
FavaAPIError – If the query response is an error.
- query_to_file(entries, query_string, result_format)¶
Get query result as file.
- Parameters:
- Returns:
tuple
[str
,BytesIO
] – A tuple (name, data), where name is either ‘query_result’ or the name of a custom query if the query string is ‘run name_of_query’.data
contains the file contents.- Raises:
FavaAPIError – If the result format is not supported or the
query failed. –
- exception fava.core.query_shell.TooManyRunArgsError(args)¶
Too many args to run: ‘{args}’.
fava.core.tree¶
Account balance trees.
- class fava.core.tree.SerialisedTreeNode(account, balance, balance_children, children, has_txns)¶
A serialised TreeNode.
-
balance:
SimpleCounterInventory
¶
-
balance_children:
SimpleCounterInventory
¶
-
children:
Sequence
[SerialisedTreeNode
]¶
-
balance:
- class fava.core.tree.SerialisedTreeNodeWithCost(account, balance, balance_children, children, has_txns, cost, cost_children)¶
A serialised TreeNode with cost.
-
cost:
SimpleCounterInventory
¶
-
cost_children:
SimpleCounterInventory
¶
-
cost:
- class fava.core.tree.Tree(entries=None, create_accounts=None)¶
Account tree.
- Parameters:
- ancestors(name)¶
Ancestors of an account.
- cap(options, unrealized_account)¶
Transfer Income and Expenses, add conversions and unrealized gains.
- Parameters:
options (
BeancountOptions
) – The Beancount options.unrealized_account (
str
) – The name of the account to post unrealized gains to (as a subaccount of Equity).
- Return type:
- get(name, *, insert=False)¶
Get an account.
- insert(name, balance)¶
Insert account with a balance.
Insert account and update its balance and the balances of its ancestors.
- Parameters:
name (
str
) – An account name.balance (
CounterInventory
) – The balance of the account.
- Return type:
- net_profit(options, account_name)¶
Calculate the net profit.
- Parameters:
options (
BeancountOptions
) – The Beancount options.account_name (
str
) – The name to use for the account containing the net profit.
- Return type:
- class fava.core.tree.TreeNode(name)¶
A node in the account tree.
- balance¶
The account balance.
- balance_children¶
The cumulative account balance.
- has_txns¶
Whether the account has any transactions.
- serialise(conversion, prices, end, *, with_cost=False)¶
Serialise the account.
- Parameters:
conversion (
str
|Conversion
) – The conversion to use.prices (
FavaPriceMap
) – The price map to use.with_cost (
bool
) – Additionally convert to cost.
- Return type:
- serialise_with_context()¶
Serialise, getting all parameters from Flask context.
- Return type:
fava.core.watcher¶
A simple file and folder watcher.
- class fava.core.watcher.Watcher¶
A simple file and folder watcher.
For folders, only checks mtime of the folder and all subdirectories. So a file change won’t be noticed, but only new/deleted files.