API Reference¶
Note
There's no stability guarantee as this is just for internal purposes currently.
Core Modules¶
rustfava.core
¶
This module provides the data required by Fava's reports.
EntryNotFoundForHashError
¶
StatementNotFoundError
¶
StatementMetadataInvalidError
¶
Bases: RustfavaAPIError
Statement metadata not found or invalid.
Source code in src/rustfava/core/__init__.py
JournalPage
dataclass
¶
FilteredLedger
¶
Filtered Beancount ledger.
Source code in src/rustfava/core/__init__.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
end_date
property
¶
The date to use for prices.
entries_with_all_prices
cached
property
¶
The filtered entries, with all prices added back in for queries.
entries_without_prices
cached
property
¶
The filtered entries, without prices for journals.
root_tree
cached
property
¶
A root tree.
root_tree_closed
cached
property
¶
A root tree for the balance sheet.
__init__(ledger, *, account=None, filter=None, time=None)
¶
Create a filtered view of a ledger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ledger
|
RustfavaLedger
|
The ledger to filter. |
required |
account
|
str | None
|
The account filter. |
None
|
filter
|
str | None
|
The advanced filter. |
None
|
time
|
str | None
|
The time filter. |
None
|
Source code in src/rustfava/core/__init__.py
interval_ranges(interval)
¶
Yield date ranges corresponding to interval boundaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval
|
Interval
|
The interval to yield ranges for. |
required |
Source code in src/rustfava/core/__init__.py
prices(base, quote)
¶
List all prices for a pair of commodities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
str
|
The price base. |
required |
quote
|
str
|
The price quote. |
required |
Source code in src/rustfava/core/__init__.py
account_is_closed(account_name)
¶
Check if the account is closed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
account_name
|
str
|
An account name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the account is closed before the end date of the current |
bool
|
time filter. |
Source code in src/rustfava/core/__init__.py
paginate_journal(page, per_page=1000, order='desc')
¶
Get entries for a journal page with pagination info.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
int
|
Page number (1-indexed). |
required |
order
|
Literal['asc', 'desc']
|
Datewise order to sort in |
'desc'
|
per_page
|
int
|
Number of entries per page. |
1000
|
Returns:
| Type | Description |
|---|---|
JournalPage | None
|
A JournalPage, containing a list of entries as (global_index, |
JournalPage | None
|
directive) tuples in reverse chronological order and the total |
JournalPage | None
|
number of pages. |
Source code in src/rustfava/core/__init__.py
RustfavaLedger
¶
Interface for a Beancount ledger.
Source code in src/rustfava/core/__init__.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 | |
mtime
property
¶
The timestamp to the latest change of the underlying files.
errors
property
¶
The errors that the Beancount loading plus Fava module errors.
root_accounts
property
¶
The five root accounts.
__init__(path, *, poll_watcher=False)
¶
Create an interface for a Beancount ledger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the main Beancount file. |
required |
poll_watcher
|
bool
|
Whether to use the polling file watcher. |
False
|
Source code in src/rustfava/core/__init__.py
load_file()
¶
Load the main file and all included files and set attributes.
Source code in src/rustfava/core/__init__.py
join_path(*args)
¶
paths_to_watch()
¶
Get paths to included files and document directories.
Returns:
| Type | Description |
|---|---|
tuple[Sequence[Path], Sequence[Path]]
|
A tuple (files, directories). |
Source code in src/rustfava/core/__init__.py
changed()
¶
Check if the file needs to be reloaded.
Returns:
| Type | Description |
|---|---|
bool
|
True if a change in one of the included files or a change in a |
bool
|
document folder was detected and the file has been reloaded. |
Source code in src/rustfava/core/__init__.py
interval_balances(filtered, interval, account_name, *, accumulate=False)
¶
Balances by interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filtered
|
FilteredLedger
|
The currently filtered ledger. |
required |
interval
|
Interval
|
An interval. |
required |
account_name
|
str
|
An account name. |
required |
accumulate
|
bool
|
A boolean, |
False
|
Returns:
| Type | Description |
|---|---|
tuple[Sequence[Tree], Sequence[DateRange]]
|
A pair of a list of Tree instances and the intervals. |
Source code in src/rustfava/core/__init__.py
account_journal(filtered, account_name, conversion, *, with_children)
¶
Journal for an account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filtered
|
FilteredLedger
|
The currently filtered ledger. |
required |
account_name
|
str
|
An account name. |
required |
conversion
|
str | Conversion
|
The conversion to use. |
required |
with_children
|
bool
|
Whether to include postings of subaccounts of the account. |
required |
Yields:
| Type | Description |
|---|---|
Iterable[tuple[int, Directive, SimpleCounterInventory, SimpleCounterInventory]]
|
Tuples of |
Source code in src/rustfava/core/__init__.py
context(entry_hash)
¶
Context for an entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry_hash
|
str
|
Hash of entry. |
required |
Returns:
| Type | Description |
|---|---|
Directive
|
A tuple |
Mapping[str, Sequence[str]] | None
|
(unique) entry with the given |
Mapping[str, Sequence[str]] | None
|
Balance or Transaction then |
tuple[Directive, Mapping[str, Sequence[str]] | None, Mapping[str, Sequence[str]] | None]
|
the balances before and after the entry of the affected accounts. |
Source code in src/rustfava/core/__init__.py
commodity_pairs()
¶
List pairs of commodities.
Returns:
| Type | Description |
|---|---|
Sequence[tuple[str, str]]
|
A list of pairs of commodities. Pairs of operating currencies will |
Sequence[tuple[str, str]]
|
be given in both directions not just in the one found in file. |
Source code in src/rustfava/core/__init__.py
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:
| Name | Type | Description | Default |
|---|---|---|---|
entry_hash
|
str
|
Hash of the entry containing the path in its metadata. |
required |
metadata_key
|
str
|
The key that the path should be in. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The filename of the matching document entry. |
Raises:
| Type | Description |
|---|---|
StatementMetadataInvalidError
|
If the metadata at the given key is invalid. |
StatementNotFoundError
|
If no matching document is found. |
Source code in src/rustfava/core/__init__.py
accounts
¶
Account close date and metadata.
LastEntry
dataclass
¶
AccountData
dataclass
¶
Holds information about an account.
Source code in src/rustfava/core/accounts.py
AccountDict
¶
Bases: FavaModule, dict[str, AccountData]
Account info dictionary.
Source code in src/rustfava/core/accounts.py
get_last_entry(txn_postings)
¶
Last entry.
Source code in src/rustfava/core/accounts.py
uptodate_status(txn_postings)
¶
Status of the last balance or transaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
txn_postings
|
Sequence[Directive | TransactionPosting]
|
The TransactionPosting for the account. |
required |
Returns:
| Type | Description |
|---|---|
Literal['green', 'yellow', 'red'] | None
|
A status string for the last balance or transaction of the account. |
Literal['green', 'yellow', 'red'] | None
|
|
Literal['green', 'yellow', 'red'] | None
|
|
Literal['green', 'yellow', 'red'] | None
|
|
Source code in src/rustfava/core/accounts.py
balance_string(tree_node)
¶
Balance directive for the given account for today.
Source code in src/rustfava/core/accounts.py
attributes
¶
Attributes for auto-completion.
AttributesModule
¶
Bases: FavaModule
Some attributes of the ledger (mostly for auto-completion).
Source code in src/rustfava/core/attributes.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
narrations
property
¶
Get the narrations of all transactions.
payee_accounts(payee)
¶
Rank accounts for the given payee.
Source code in src/rustfava/core/attributes.py
payee_transaction(payee)
¶
Get the last transaction for a payee.
Source code in src/rustfava/core/attributes.py
narration_transaction(narration)
¶
Get the last transaction for a narration.
Source code in src/rustfava/core/attributes.py
get_active_years(entries, fye)
¶
Return active years, with support for fiscal years.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
Sequence[Directive]
|
Beancount entries |
required |
fye
|
FiscalYearEnd
|
fiscal year end |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
A reverse sorted list of years or fiscal years that occur in the |
list[str]
|
entries. |
Source code in src/rustfava/core/attributes.py
budgets
¶
Parsing and computing budgets.
BudgetDict = dict[str, list[Budget]]
module-attribute
¶
A map of account names to lists of budget entries.
Budget
¶
BudgetError
dataclass
¶
BudgetModule
¶
Bases: FavaModule
Parses budget entries.
Source code in src/rustfava/core/budgets.py
parse_budgets(custom_entries)
¶
Parse budget directives from custom entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_entries
|
Sequence[Custom]
|
the Custom entries to parse budgets from. |
required |
Returns:
| Type | Description |
|---|---|
tuple[BudgetDict, Sequence[BudgetError]]
|
A dict of accounts to lists of budgets. |
Example
2015-04-09 custom "budget" Expenses:Books "monthly" 20.00 EUR
Source code in src/rustfava/core/budgets.py
calculate_budget(budgets, account, date_from, date_to)
¶
Calculate budget for an account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budgets
|
BudgetDict
|
A list of :class: |
required |
account
|
str
|
An account name. |
required |
date_from
|
date
|
Starting date. |
required |
date_to
|
date
|
End date (exclusive). |
required |
Returns:
| Type | Description |
|---|---|
Mapping[str, Decimal]
|
A dictionary of currency to Decimal with the budget for the |
Mapping[str, Decimal]
|
specified account and period. |
Source code in src/rustfava/core/budgets.py
calculate_budget_children(budgets, account, date_from, date_to)
¶
Calculate budget for an account including budgets of its children.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budgets
|
BudgetDict
|
A list of :class: |
required |
account
|
str
|
An account name. |
required |
date_from
|
date
|
Starting date. |
required |
date_to
|
date
|
End date (exclusive). |
required |
Returns:
| Type | Description |
|---|---|
Mapping[str, Decimal]
|
A dictionary of currency to Decimal with the budget for the |
Mapping[str, Decimal]
|
specified account and period. |
Source code in src/rustfava/core/budgets.py
charts
¶
Provide data suitable for rustfava's charts.
RustfavaJSONProvider
¶
Bases: JSONProvider
Use custom JSON encoder and decoder.
Source code in src/rustfava/core/charts.py
DateAndBalance
dataclass
¶
DateAndBalanceWithBudget
dataclass
¶
Balance at a date with a budget.
Source code in src/rustfava/core/charts.py
ChartModule
¶
Bases: FavaModule
Return data for the various charts in rustfava.
Source code in src/rustfava/core/charts.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
hierarchy(filtered, account_name, conversion)
¶
Render an account tree.
Source code in src/rustfava/core/charts.py
interval_totals(filtered, interval, accounts, conversion, *, invert=False)
¶
Render totals for account (or accounts) in the intervals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filtered
|
FilteredLedger
|
The filtered ledger. |
required |
interval
|
Interval
|
An interval. |
required |
accounts
|
str | tuple[str, ...]
|
A single account (str) or a tuple of accounts. |
required |
conversion
|
str | Conversion
|
The conversion to use. |
required |
invert
|
bool
|
invert all numbers. |
False
|
Yields:
| Type | Description |
|---|---|
Iterable[DateAndBalanceWithBudget]
|
The balances and budgets for the intervals. |
Source code in src/rustfava/core/charts.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
linechart(filtered, account_name, conversion)
¶
Get the balance of an account as a line chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filtered
|
FilteredLedger
|
The filtered ledger. |
required |
account_name
|
str
|
A string. |
required |
conversion
|
str | Conversion
|
The conversion to use. |
required |
Yields:
| Type | Description |
|---|---|
Iterable[DateAndBalance]
|
Dicts for all dates on which the balance of the given |
Iterable[DateAndBalance]
|
account has changed containing the balance (in units) of the |
Iterable[DateAndBalance]
|
account at that date. |
Source code in src/rustfava/core/charts.py
net_worth(filtered, interval, conversion)
¶
Compute net worth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filtered
|
FilteredLedger
|
The filtered ledger. |
required |
interval
|
Interval
|
A string for the interval. |
required |
conversion
|
str | Conversion
|
The conversion to use. |
required |
Yields:
| Type | Description |
|---|---|
Iterable[DateAndBalance]
|
Dicts for all ends of the given interval containing the |
Iterable[DateAndBalance]
|
net worth (Assets + Liabilities) separately converted to all |
Iterable[DateAndBalance]
|
operating currencies. |
Source code in src/rustfava/core/charts.py
dumps(obj, **_kwargs)
¶
commodities
¶
Attributes for auto-completion.
CommoditiesModule
¶
Bases: FavaModule
Details about the currencies and commodities.
Source code in src/rustfava/core/commodities.py
conversion
¶
Commodity conversion helpers for Fava.
All functions in this module will be automatically added as template filters.
Conversion
¶
Bases: ABC
A conversion.
Source code in src/rustfava/core/conversion.py
apply(inventory, prices, date=None)
abstractmethod
¶
Apply the conversion to an inventory (CounterInventory).
get_cost(pos)
¶
Return the total cost of a Position.
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:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
Position
|
A Position. |
required |
prices
|
RustfavaPriceMap
|
A rustfavaPriceMap |
required |
date
|
date | None
|
A datetime.date instance to evaluate the value at, or None. |
None
|
Returns:
| Type | Description |
|---|---|
Amount
|
An Amount, with value converted or if the conversion failed just the |
Amount
|
cost value (or the units if the position has no cost). |
Source code in src/rustfava/core/conversion.py
convert_position(pos, target_currency, prices, date=None)
¶
Get the value of a Position in a particular currency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
Position
|
A Position. |
required |
target_currency
|
str
|
The target currency to convert to. |
required |
prices
|
RustfavaPriceMap
|
A rustfavaPriceMap |
required |
date
|
date | None
|
A datetime.date instance to evaluate the value at, or None. |
None
|
Returns:
| Type | Description |
|---|---|
Amount
|
An Amount, with value converted or if the conversion failed just the |
Amount
|
cost value (or the units if the position has no cost). |
Source code in src/rustfava/core/conversion.py
conversion_from_str(value)
¶
Parse a conversion string.
Source code in src/rustfava/core/conversion.py
cost_or_value(inventory, conversion, prices, date=None)
¶
Get the cost or value of an inventory.
Source code in src/rustfava/core/conversion.py
documents
¶
Document path related helpers.
NotADocumentsFolderError
¶
NotAValidAccountError
¶
is_document_or_import_file(filename, ledger)
¶
Check whether the filename is a document or in an import directory.
This is a security validation function that prevents path traversal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The filename to check. |
required |
ledger
|
RustfavaLedger
|
The RustfavaLedger. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether this is one of the documents or a path in an import dir. |
Source code in src/rustfava/core/documents.py
filepath_in_document_folder(documents_folder, account, filename, ledger)
¶
File path for a document in the folder for an account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents_folder
|
str
|
The documents folder. |
required |
account
|
str
|
The account to choose the subfolder for. |
required |
filename
|
str
|
The filename of the document. |
required |
ledger
|
RustfavaLedger
|
The RustfavaLedger. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The path that the document should be saved at. |
Source code in src/rustfava/core/documents.py
extensions
¶
Fava extensions.
ExtensionDetails
dataclass
¶
ExtensionModule
¶
Bases: FavaModule
Fava extensions.
Source code in src/rustfava/core/extensions.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
extension_details
property
¶
Extension information to provide to the Frontend.
get_extension(name)
¶
after_load_file()
¶
before_request()
¶
after_entry_modified(entry, new_lines)
¶
Run all after_entry_modified hooks.
after_insert_entry(entry)
¶
after_delete_entry(entry)
¶
after_insert_metadata(entry, key, value)
¶
Run all after_insert_metadata hooks.
fava_options
¶
rustfava's options.
Options for rustfava 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.
OptionError
dataclass
¶
InsertEntryOption
dataclass
¶
Insert option.
An option that determines where entries for matching accounts should be inserted.
Source code in src/rustfava/core/fava_options.py
RustfavaOptions
dataclass
¶
Options for rustfava that can be set in the Beancount file.
Source code in src/rustfava/core/fava_options.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
set_collapse_pattern(value)
¶
Set the collapse_pattern option.
Source code in src/rustfava/core/fava_options.py
set_default_file(value, filename)
¶
set_fiscal_year_end(value)
¶
Set the fiscal_year_end option.
set_import_dirs(value)
¶
set_insert_entry(value, date, filename, lineno)
¶
Set the insert_entry option.
Source code in src/rustfava/core/fava_options.py
set_language(value)
¶
Set the locale option.
Source code in src/rustfava/core/fava_options.py
set_locale(value)
¶
parse_option_custom_entry(entry, options)
¶
Parse a single custom fava-option entry and set option accordingly.
Source code in src/rustfava/core/fava_options.py
parse_options(custom_entries)
¶
Parse custom entries for rustfava options.
The format for option entries is the following::
2016-04-01 custom "fava-option" "[name]" "[value]"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_entries
|
Sequence[Custom]
|
A list of Custom entries. |
required |
Returns:
| Type | Description |
|---|---|
RustfavaOptions
|
A tuple (options, errors) where options is a dictionary of all options |
list[OptionError]
|
to values, and errors contains possible parsing errors. |
Source code in src/rustfava/core/fava_options.py
file
¶
Reading/writing Beancount files.
NonSourceFileError
¶
Bases: RustfavaAPIError
Trying to read a non-source file.
Source code in src/rustfava/core/file.py
ExternallyChangedError
¶
GeneratedEntryError
¶
Bases: RustfavaAPIError
The entry is generated and cannot be edited.
Source code in src/rustfava/core/file.py
InvalidUnicodeError
¶
Bases: RustfavaAPIError
The source file contains invalid unicode.
Source code in src/rustfava/core/file.py
FileModule
¶
Bases: FavaModule
Functions related to reading/writing to Beancount files.
Source code in src/rustfava/core/file.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
get_source(path)
¶
Get source files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The path of the file. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
A string with the file contents and the |
Raises:
| Type | Description |
|---|---|
NonSourceFileError
|
If the file is not one of the source files. |
InvalidUnicodeError
|
If the file contains invalid unicode. |
Source code in src/rustfava/core/file.py
set_source(path, source, sha256sum)
¶
Write to source file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The path of the file. |
required |
source
|
str
|
A string with the file contents. |
required |
sha256sum
|
str
|
Hash of the file. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The |
Raises:
| Type | Description |
|---|---|
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. |
Source code in src/rustfava/core/file.py
insert_metadata(entry_hash, basekey, value)
¶
Insert metadata into a file at lineno.
Also, prevent duplicate keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry_hash
|
str
|
Hash of an entry. |
required |
basekey
|
str
|
Key to insert metadata for. |
required |
value
|
str
|
Metadate value to insert. |
required |
Source code in src/rustfava/core/file.py
save_entry_slice(entry_hash, source_slice, sha256sum)
¶
Save slice of the source file for an entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry_hash
|
str
|
Hash of an entry. |
required |
source_slice
|
str
|
The lines that the entry should be replaced with. |
required |
sha256sum
|
str
|
The sha256sum of the current lines of the entry. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The |
Raises:
| Type | Description |
|---|---|
RustfavaAPIError
|
If the entry is not found or the file changed. |
Source code in src/rustfava/core/file.py
delete_entry_slice(entry_hash, sha256sum)
¶
Delete slice of the source file for an entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry_hash
|
str
|
Hash of an entry. |
required |
sha256sum
|
str
|
The sha256sum of the current lines of the entry. |
required |
Raises:
| Type | Description |
|---|---|
RustfavaAPIError
|
If the entry is not found or the file changed. |
Source code in src/rustfava/core/file.py
insert_entries(entries)
¶
Insert entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
Sequence[Directive]
|
A list of entries. |
required |
Source code in src/rustfava/core/file.py
render_entries(entries)
¶
Return entries in Beancount format.
Only renders :class:.Balance and :class:.Transaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
Sequence[Directive]
|
A list of entries. |
required |
Yields:
| Type | Description |
|---|---|
Iterable[Markup]
|
The entries rendered in Beancount format. |
Source code in src/rustfava/core/file.py
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.
Source code in src/rustfava/core/file.py
find_entry_lines(lines, lineno)
¶
Lines of entry starting at lineno.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines
|
Sequence[str]
|
A list of lines. |
required |
lineno
|
int
|
The 0-based line-index to start at. |
required |
Source code in src/rustfava/core/file.py
get_entry_slice(entry)
¶
Get slice of the source file for an entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
Directive
|
An entry. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string containing the lines of the entry and the |
str
|
these lines. |
Raises:
| Type | Description |
|---|---|
GeneratedEntryError
|
If the entry is generated and cannot be edited. |
Source code in src/rustfava/core/file.py
save_entry_slice(entry, source_slice, sha256sum)
¶
Save slice of the source file for an entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
Directive
|
An entry. |
required |
source_slice
|
str
|
The lines that the entry should be replaced with. |
required |
sha256sum
|
str
|
The sha256sum of the current lines of the entry. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The |
Raises:
| Type | Description |
|---|---|
ExternallyChangedError
|
If the file was changed externally. |
GeneratedEntryError
|
If the entry is generated and cannot be edited. |
Source code in src/rustfava/core/file.py
delete_entry_slice(entry, sha256sum)
¶
Delete slice of the source file for an entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
Directive
|
An entry. |
required |
sha256sum
|
str
|
The sha256sum of the current lines of the entry. |
required |
Raises:
| Type | Description |
|---|---|
ExternallyChangedError
|
If the file was changed externally. |
GeneratedEntryError
|
If the entry is generated and cannot be edited. |
Source code in src/rustfava/core/file.py
insert_entry(entry, default_filename, insert_options, currency_column, indent)
¶
Insert an entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
Directive
|
An entry. |
required |
default_filename
|
str
|
The default file to insert into if no option matches. |
required |
insert_options
|
Sequence[InsertEntryOption]
|
Insert options. |
required |
currency_column
|
int
|
The column to align currencies at. |
required |
indent
|
int
|
Number of indent spaces. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Path, Sequence[InsertEntryOption]]
|
A changed path and list of updated insert options. |
Source code in src/rustfava/core/file.py
find_insert_position(entry, insert_options, default_filename)
¶
Find insert position for an entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
Directive
|
An entry. |
required |
insert_options
|
Sequence[InsertEntryOption]
|
A list of InsertOption. |
required |
default_filename
|
str
|
The default file to insert into if no option matches. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, int | None]
|
A tuple of the filename and the line number. |
Source code in src/rustfava/core/file.py
filters
¶
Entry filters.
FilterError
¶
Bases: RustfavaAPIError
Filter exception.
Source code in src/rustfava/core/filters.py
FilterParseError
¶
FilterIllegalCharError
¶
TimeFilterParseError
¶
Token
¶
A token having a certain type and value.
The lexer attribute only exists since PLY writes to it in case of a parser error.
Source code in src/rustfava/core/filters.py
FilterSyntaxLexer
¶
Lexer for Fava's filter syntax.
Source code in src/rustfava/core/filters.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
lex(data)
¶
A generator yielding all tokens in a given line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str
|
A string, the line to lex. |
required |
Yields:
| Type | Description |
|---|---|
Iterable[Token]
|
All Tokens in the line. |
Source code in src/rustfava/core/filters.py
Match
¶
Match a string.
Source code in src/rustfava/core/filters.py
MatchAmount
¶
Matches an amount.
Source code in src/rustfava/core/filters.py
FilterSyntaxParser
¶
Source code in src/rustfava/core/filters.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
p_filter(p)
¶
p_expr(p)
¶
p_expr_all(p)
¶
expr : ALL expr ')'
Source code in src/rustfava/core/filters.py
p_expr_any(p)
¶
expr : ANY expr ')'
Source code in src/rustfava/core/filters.py
p_expr_parentheses(p)
¶
p_expr_and(p)
¶
expr : expr expr %prec AND
Source code in src/rustfava/core/filters.py
p_expr_or(p)
¶
expr : expr ',' expr
p_expr_negated(p)
¶
p_simple_expr_TAG(p)
¶
simple_expr : TAG
Source code in src/rustfava/core/filters.py
p_simple_expr_LINK(p)
¶
simple_expr : LINK
Source code in src/rustfava/core/filters.py
p_simple_expr_STRING(p)
¶
simple_expr : STRING
Source code in src/rustfava/core/filters.py
p_simple_expr_key(p)
¶
KEY EQ_OP STRING
| KEY CMP_OP NUMBER
Source code in src/rustfava/core/filters.py
p_simple_expr_units(p)
¶
simple_expr : CMP_OP NUMBER
Source code in src/rustfava/core/filters.py
EntryFilter
¶
Bases: ABC
Filters a list of entries.
Source code in src/rustfava/core/filters.py
TimeFilter
¶
Bases: EntryFilter
Filter by dates.
Source code in src/rustfava/core/filters.py
AdvancedFilter
¶
Bases: EntryFilter
Filter by tags and links and keys.
Source code in src/rustfava/core/filters.py
AccountFilter
¶
Bases: EntryFilter
Filter by account.
The filter string can either be a regular expression or a parent account.
Source code in src/rustfava/core/filters.py
group_entries
¶
Entries grouped by type.
EntriesByType
¶
Bases: NamedTuple
Entries grouped by type.
Source code in src/rustfava/core/group_entries.py
TransactionPosting
¶
group_entries_by_type(entries)
¶
Group entries by type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
Sequence[Directive]
|
A list of entries to group. |
required |
Returns:
| Type | Description |
|---|---|
EntriesByType
|
A namedtuple containing the grouped lists of entries. |
Source code in src/rustfava/core/group_entries.py
group_entries_by_account(entries)
¶
Group entries by account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
Sequence[Directive]
|
A list of entries. |
required |
Returns:
| Type | Description |
|---|---|
Mapping[str, Sequence[Directive | TransactionPosting]]
|
A dict mapping account names to their entries. |
Source code in src/rustfava/core/group_entries.py
ingest
¶
Ingest helper functions.
IngestError
dataclass
¶
ImporterMethodCallError
¶
Bases: RustfavaAPIError
Error calling one of the importer methods.
Source code in src/rustfava/core/ingest.py
ImporterInvalidTypeError
¶
Bases: RustfavaAPIError
One of the importer methods returned an unexpected type.
Source code in src/rustfava/core/ingest.py
ImporterExtractError
¶
Bases: ImporterMethodCallError
Error calling extract for importer.
Source code in src/rustfava/core/ingest.py
MissingImporterConfigError
¶
MissingImporterDirsError
¶
Bases: RustfavaAPIError
You need to set at least one imports-dir.
Source code in src/rustfava/core/ingest.py
ImportConfigLoadError
¶
FileImportInfo
dataclass
¶
FileImporters
dataclass
¶
WrappedImporter
¶
A wrapper to safely call importer methods.
Source code in src/rustfava/core/ingest.py
name
property
¶
Get the name of the importer.
identify(path)
¶
Whether the importer is matching the file.
Source code in src/rustfava/core/ingest.py
file_import_info(path)
¶
Generate info about a file with an importer.
Source code in src/rustfava/core/ingest.py
IngestModule
¶
Bases: FavaModule
Exposes ingest functionality.
Source code in src/rustfava/core/ingest.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | |
module_path
property
¶
The path to the importer configuration.
import_data()
¶
Identify files and importers that can be imported.
Returns:
| Type | Description |
|---|---|
list[FileImporters]
|
A list of :class: |
Source code in src/rustfava/core/ingest.py
extract(filename, importer_name)
¶
Extract entries from filename with the specified importer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The full path to a file. |
required |
importer_name
|
str
|
The name of an importer that matched the file. |
required |
Returns:
| Type | Description |
|---|---|
list[Directive]
|
A list of new imported entries. |
Source code in src/rustfava/core/ingest.py
walk_dir(directory)
¶
Walk through all files in dir.
Ignores common dot-directories like .git, .cache. .venv, see IGNORE_DIRS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
Path
|
The directory to start in. |
required |
Yields:
| Type | Description |
|---|---|
Iterable[Path]
|
All full paths under directory, ignoring some directories. |
Source code in src/rustfava/core/ingest.py
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.
Source code in src/rustfava/core/ingest.py
find_imports(config, directory)
¶
Pair files and matching importers.
Yields:
| Type | Description |
|---|---|
Iterable[FileImporters]
|
For each file in directory, a pair of its filename and the matching |
Iterable[FileImporters]
|
importers. |
Source code in src/rustfava/core/ingest.py
extract_from_file(wrapped_importer, path, existing_entries)
¶
Import entries from a document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wrapped_importer
|
WrappedImporter
|
The importer instance to handle the document. |
required |
path
|
Path
|
Filesystem path to the document. |
required |
existing_entries
|
Sequence[Directive]
|
Existing entries. |
required |
Returns:
| Type | Description |
|---|---|
list[Directive]
|
The list of imported entries. |
Source code in src/rustfava/core/ingest.py
load_import_config(module_path)
¶
Load the given import config and extract importers and hooks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_path
|
Path
|
Path to the import config. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Mapping[str, WrappedImporter], Hooks]
|
A pair of the importers (by name) and the list of hooks. |
Source code in src/rustfava/core/ingest.py
filepath_in_primary_imports_folder(filename, ledger)
¶
File path for a document to upload to the primary import folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The filename of the document. |
required |
ledger
|
RustfavaLedger
|
The RustfavaLedger. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The path that the document should be saved at. |
Source code in src/rustfava/core/ingest.py
inventory
¶
Alternative implementation of Beancount's Inventory.
SimpleCounterInventory
¶
Bases: dict[str, Decimal]
A simple inventory mapping just strings to numbers.
Source code in src/rustfava/core/inventory.py
is_empty()
¶
add(key, number)
¶
reduce(reducer, *args, **_kwargs)
¶
Reduce inventory.
Source code in src/rustfava/core/inventory.py
CounterInventory
¶
Bases: dict[InventoryKey, Decimal]
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).
Source code in src/rustfava/core/inventory.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
is_empty()
¶
add(key, number)
¶
to_strings()
¶
Print as a list of strings (e.g. for snapshot tests).
Source code in src/rustfava/core/inventory.py
reduce(reducer, *args, **_kwargs)
¶
Reduce inventory.
Note that this returns a simple :class:CounterInventory with just
currencies as keys.
Source code in src/rustfava/core/inventory.py
add_amount(amount, cost=None)
¶
add_position(pos)
¶
Add a Position or Posting to the inventory.
add_inventory(counter)
¶
Add another :class:CounterInventory.
Source code in src/rustfava/core/inventory.py
misc
¶
Some miscellaneous reports.
FavaError
dataclass
¶
FavaMisc
¶
Bases: FavaModule
Provides access to some miscellaneous reports.
Source code in src/rustfava/core/misc.py
errors
property
¶
An error if no operating currency is set.
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"
Source code in src/rustfava/core/misc.py
upcoming_events(events, max_delta)
¶
Parse entries for upcoming events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
Sequence[Event]
|
A list of events. |
required |
max_delta
|
int
|
Number of days that should be considered. |
required |
Returns:
| Type | Description |
|---|---|
Sequence[Event]
|
A list of the Events in entries that are less than |
Sequence[Event]
|
away. |
Source code in src/rustfava/core/misc.py
align(string, currency_column)
¶
Align currencies in one column.
Source code in src/rustfava/beans/str.py
module_base
¶
Base class for the "modules" of rustfavaLedger.
FavaModule
¶
Base class for the "modules" of rustfavaLedger.
Source code in src/rustfava/core/module_base.py
number
¶
Formatting numbers.
DecimalFormatModule
¶
Bases: FavaModule
Formatting numbers.
Source code in src/rustfava/core/number.py
__call__(value, currency=None)
¶
Format a decimal to the right number of decimal digits with locale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Decimal
|
A decimal number. |
required |
currency
|
str | None
|
A currency string or None. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A string, the formatted decimal. |
Source code in src/rustfava/core/number.py
get_locale_format(locale, precision)
¶
Obtain formatting pattern for the given locale and precision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
locale
|
Locale | None
|
An optional locale. |
required |
precision
|
int
|
The precision. |
required |
Returns:
| Type | Description |
|---|---|
Formatter
|
A function that renders Decimals to strings as desired. |
Source code in src/rustfava/core/number.py
query
¶
Query result types.
QueryResultTable
dataclass
¶
QueryResultText
dataclass
¶
BaseColumn
dataclass
¶
BoolColumn
dataclass
¶
DecimalColumn
dataclass
¶
IntColumn
dataclass
¶
StrColumn
dataclass
¶
DateColumn
dataclass
¶
PositionColumn
dataclass
¶
SetColumn
dataclass
¶
AmountColumn
dataclass
¶
ObjectColumn
dataclass
¶
InventoryColumn
dataclass
¶
Bases: BaseColumn
An inventory query column.
Source code in src/rustfava/core/query.py
serialise(val)
staticmethod
¶
Serialise an inventory.
Rustledger returns inventory as a dict of currency -> Decimal.
Source code in src/rustfava/core/query.py
query_shell
¶
For running BQL queries in Fava.
FavaShellError
¶
QueryNotFoundError
¶
TooManyRunArgsError
¶
QueryCompilationError
¶
QueryParseError
¶
NonExportableQueryError
¶
Bases: FavaShellError
Only queries that return a table can be printed to a file.
Source code in src/rustfava/core/query_shell.py
FavaQueryRunner
¶
Runs BQL queries using rustledger.
Source code in src/rustfava/core/query_shell.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
run(entries, query)
¶
Run a query, returning cursor or text result.
Source code in src/rustfava/core/query_shell.py
QueryShell
¶
Bases: FavaModule
A Fava module to run BQL queries.
Source code in src/rustfava/core/query_shell.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
execute_query_serialised(entries, query)
¶
Run a query and returns its serialised result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
Sequence[Directive]
|
The entries to run the query on. |
required |
query
|
str
|
A query string. |
required |
Returns:
| Type | Description |
|---|---|
QueryResultTable | QueryResultText
|
Either a table or a text result (depending on the query). |
Raises:
| Type | Description |
|---|---|
RustfavaAPIError
|
If the query response is an error. |
Source code in src/rustfava/core/query_shell.py
query_to_file(entries, query_string, result_format)
¶
Get query result as file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
Sequence[Directive]
|
The entries to run the query on. |
required |
query_string
|
str
|
A string, the query to run. |
required |
result_format
|
str
|
The file format to save to. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A tuple (name, data), where name is either 'query_result' or the |
BytesIO
|
name of a custom query if the query string is 'run name_of_query'. |
tuple[str, BytesIO]
|
|
Raises:
| Type | Description |
|---|---|
RustfavaAPIError
|
If the result format is not supported or the |
Source code in src/rustfava/core/query_shell.py
tree
¶
Account balance trees.
SerialisedTreeNode
dataclass
¶
A serialised TreeNode.
Source code in src/rustfava/core/tree.py
TreeNode
¶
A node in the account tree.
Source code in src/rustfava/core/tree.py
serialise(conversion, prices, end, *, with_cost=False)
¶
Serialise the account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversion
|
Conversion
|
The conversion to use. |
required |
prices
|
RustfavaPriceMap
|
The price map to use. |
required |
end
|
date | None
|
A date to use for cost conversions. |
required |
with_cost
|
bool
|
Additionally convert to cost. |
False
|
Source code in src/rustfava/core/tree.py
serialise_with_context()
¶
Serialise, getting all parameters from Flask context.
Tree
¶
Bases: dict[str, TreeNode]
Account tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
Iterable[Directive | Directive] | None
|
A list of entries to compute balances from. |
None
|
create_accounts
|
list[str] | None
|
A list of accounts that the tree should contain. |
None
|
Source code in src/rustfava/core/tree.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
accounts
property
¶
The accounts in this tree.
ancestors(name)
¶
Ancestors of an account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
An account name. |
required |
Yields:
| Type | Description |
|---|---|
Iterable[TreeNode]
|
The ancestors of the given account from the bottom up. |
Source code in src/rustfava/core/tree.py
insert(name, balance)
¶
Insert account with a balance.
Insert account and update its balance and the balances of its ancestors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
An account name. |
required |
balance
|
CounterInventory
|
The balance of the account. |
required |
Source code in src/rustfava/core/tree.py
get(name, *, insert=False)
¶
Get an account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
An account name. |
required |
insert
|
bool
|
If True, insert the name into the tree if it does not exist. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
TreeNode |
TreeNode
|
The account of that name or an empty account if the |
TreeNode
|
account is not in the tree. |
Source code in src/rustfava/core/tree.py
net_profit(options, account_name)
¶
Calculate the net profit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
BeancountOptions
|
The Beancount options. |
required |
account_name
|
str
|
The name to use for the account containing the net profit. |
required |
Source code in src/rustfava/core/tree.py
cap(options, unrealized_account)
¶
Transfer Income and Expenses, add conversions and unrealized gains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
BeancountOptions
|
The Beancount options. |
required |
unrealized_account
|
str
|
The name of the account to post unrealized gains to (as a subaccount of Equity). |
required |
Source code in src/rustfava/core/tree.py
watcher
¶
A simple file and folder watcher.
WatcherBase
¶
Bases: ABC
ABC for rustfava ledger file watchers.
Source code in src/rustfava/core/watcher.py
last_checked
instance-attribute
¶
Timestamp of the latest change noticed by the file watcher.
last_notified
instance-attribute
¶
Timestamp of the latest change that the watcher was notified of.
update(files, folders)
abstractmethod
¶
Update the folders/files to watch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
Iterable[Path]
|
A list of file paths. |
required |
folders
|
Iterable[Path]
|
A list of paths to folders. |
required |
check()
¶
Check for changes.
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
|
Source code in src/rustfava/core/watcher.py
notify(path)
¶
Notify the watcher of a change to a path.
Source code in src/rustfava/core/watcher.py
WatchfilesWatcher
¶
Bases: WatcherBase
A file and folder watcher using the watchfiles library.
Source code in src/rustfava/core/watcher.py
update(files, folders)
¶
Update the folders/files to watch.
Source code in src/rustfava/core/watcher.py
Watcher
¶
Bases: WatcherBase
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.
Source code in src/rustfava/core/watcher.py
update(files, folders)
¶
Application¶
rustfava.application
¶
rustfava's main WSGI application.
you can use create_app to create a rustfava WSGI app for a given list of files.
To start a simple server::
from rustfava.application import create_app
app = create_app(['/path/to/file.beancount'])
app.run('localhost', 5000)
static_url(filename)
¶
Return a static url with an mtime query string for cache busting.
Source code in src/rustfava/application.py
url_for(endpoint, **values)
¶
translations()
¶
create_app(files, *, load=False, incognito=False, read_only=False, poll_watcher=False)
¶
Create a rustfava Flask application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
Iterable[Path | str]
|
The list of Beancount files (paths). |
required |
load
|
bool
|
Whether to load the Beancount files directly. |
False
|
incognito
|
bool
|
Whether to run in incognito mode. |
False
|
read_only
|
bool
|
Whether to run in read-only mode. |
False
|
poll_watcher
|
bool
|
Whether to use old poll watcher |
False
|
Source code in src/rustfava/application.py
CLI¶
rustfava.cli
¶
The command-line interface for rustfava.
main(*, filenames=(), port=5000, host='localhost', prefix=None, incognito=False, read_only=False, debug=False, profile=False, profile_dir=None, poll_watcher=False)
¶
Start Rustfava for FILENAMES on http://
If the BEANCOUNT_FILE environment variable is set, Rustfava will use the
files (delimited by ';' on Windows and ':' on POSIX) given there in
addition to FILENAMES.
Note you can also specify command-line options via environment variables
with the RUSTFAVA_ prefix. For example, --host=0.0.0.0 is equivalent to
setting the environment variable RUSTFAVA_HOST=0.0.0.0.
Source code in src/rustfava/cli.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |