beancount.scripts

Implementation of the various scripts available from bin.

This is structured this way because we want all the significant codes under a single directory, for analysis, grepping and unit testing.

beancount.scripts.bake

Bake a Beancount input file’s web files to a directory hierarchy.

You provide a Beancount filename, an output directory, and this script runs a server and a scraper that puts all the files in the directory, and if your output name has an archive suffix, we automatically the fetched directory contents to the archive and delete them.

beancount.scripts.bake.BINARY_MATCH()

Matches zero or more characters at the beginning of the string.

beancount.scripts.bake.archive(command_template, directory, archive, quiet=False)

Archive the directory to the given tar/gz archive filename.

Parameters
  • command_template – A string, the command template to format with in order to compute the command to run.

  • directory – A string, the name of the directory to archive.

  • archive – A string, the name of the file to output.

  • quiet – A boolean, True to suppress output.

Raises
  • IOError – if the directory does not exist or if the archive name already

  • exists.

beancount.scripts.bake.archive_zip(directory, archive)

Archive the directory to the given tar/gz archive filename.

Parameters
  • directory – A string, the name of the directory to archive.

  • archive – A string, the name of the file to output.

beancount.scripts.bake.bake_to_directory(webargs, output_dir, quiet=False, full_mode=True)

Serve and bake a Beancount’s web to a directory.

Parameters
  • webargs – An argparse parsed options object with the web app arguments.

  • output_dir – A directory name. We don’t check here whether it exists or not.

  • quiet – A boolean, True to suppress web server fetch log.

  • full_mode – If true, fetch the full set of pages, not just the subset that is palatable.

Returns

True on success, False otherwise.

beancount.scripts.bake.main()
beancount.scripts.bake.normalize_filename(url)

Convert URL paths to filenames. Add .html extension if needed.

Parameters

url – A string, the url to convert.

Returns

A string, possibly with an extension appended.

Make all the links in the contents string relative to an URL.

Parameters
  • html – An lxml document node.

  • current_url – A string, the URL of the current page, a path to. a file or a directory. If the path represents a directory, the path ends with a /.

Convert a list of anchors (<a>) from an HTML tree to spans (<span>).

Parameters
  • html – An lxml document node.

  • targets – A set of string, targets to be removed.

beancount.scripts.bake.save_scraped_document(output_dir, url, response, contents, html_root, skipped_urls)

Callback function to process a document being scraped.

This converts the document to have relative links and writes out the file to the output directory.

Parameters
  • output_dir – A string, the output directory to write.

  • url – A string, the originally requested URL.

  • response – An http response as per urlopen.

  • contents – Bytes, the content of a response.

  • html_root – An lxml root node for the document, optionally. If this is provided, this avoid you having to reprocess it (for performance reasons).

  • skipped_urls – A set of the links from the file that were skipped.

beancount.scripts.check

Parse, check and realize a beancount input file.

This also measures the time it takes to run all these steps.

beancount.scripts.check.main()

beancount.scripts.deps

Check the installation dependencies and report the version numbers of each.

This is meant to be used as an error diagnostic tool.

beancount.scripts.deps.check_cdecimal()

Check that Python 3.3 or above is installed.

Returns

A triple of (package-name, version-number, sufficient) as per check_dependencies().

beancount.scripts.deps.check_dependencies()

Check the runtime dependencies and report their version numbers.

Returns

A list of pairs of (package-name, version-number, sufficient) whereby if a package has not been installed, its ‘version-number’ will be set to None. Otherwise, it will be a string with the version number in it. ‘sufficient’ will be True if the version if sufficient for this installation of Beancount.

beancount.scripts.deps.check_import(package_name, min_version=None, module_name=None)

Check that a particular module name is installed.

Parameters
  • package_name – A string, the name of the package and module to be imported to verify this works. This should have a __version__ attribute on it.

  • min_version – If not None, a string, the minimum version number we require.

  • module_name – The name of the module to import if it differs from the package name.

Returns

A triple of (package-name, version-number, sufficient) as per check_dependencies().

beancount.scripts.deps.check_python()

Check that Python 3.3 or above is installed.

Returns

A triple of (package-name, version-number, sufficient) as per check_dependencies().

beancount.scripts.deps.check_python_magic()

Check that a recent-enough version of python-magic is installed.

python-magic is an interface to libmagic, which is used by the ‘file’ tool and UNIX to identify file types. Note that there are two Python wrappers which provide the ‘magic’ import: python-magic and filemagic. The former is what we need, which appears to be more recently maintained.

Returns

A triple of (package-name, version-number, sufficient) as per check_dependencies().

beancount.scripts.deps.is_fast_decimal(decimal_module)

Return true if a fast C decimal implementattion is installed.

beancount.scripts.deps.list_dependencies(file=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>)

Check the dependencies and produce a listing on the given file.

Parameters

file – A file object to write the output to.

beancount.scripts.deps.parse_version(version_str)

Parse the version string into a comparable tuple.

Return type

str

beancount.scripts.directories

Check that document directories mirror a list of accounts correctly.

exception beancount.scripts.directories.ValidateDirectoryError

A directory validation error.

beancount.scripts.directories.validate_directories(entries, document_dirs)

Validate a directory hierarchy against a ledger’s account names.

Read a ledger’s list of account names and check that all the capitalized subdirectory names under the given roots match the account names.

Parameters
  • entries – A list of directives.

  • document_dirs – A list of string, the directory roots to walk and validate.

beancount.scripts.directories.validate_directory(accounts, document_dir)

Check a directory hierarchy against a list of valid accounts.

Walk the directory hierarchy, and for all directories with names matching that of accounts (with “:” replaced with “/”), check that they refer to an account name declared in the given list.

Parameters
  • account – A set or dict of account names.

  • document_dir – A string, the root directory to walk and validate.

Returns

An errors for each invalid directory name found.

beancount.scripts.doctor

Debugging tool for those finding bugs in Beancount.

This tool is able to dump lexer/parser state, and will provide other services in the name of debugging.

class beancount.scripts.doctor.RenderError(source, message, entry)
beancount.scripts.doctor.do_checkdeps(*unused_args)

Report on the runtime dependencies.

Parameters

unused_args – Ignored.

beancount.scripts.doctor.do_context(filename, args)

Describe the context that a particular transaction is applied to.

Parameters
  • filename – A string, which consists in the filename.

  • args – A tuple of the rest of arguments. We’re expecting the first argument to be a string which contains either a lineno integer or a filename:lineno combination (which can be used if the location is not in the top-level file).

beancount.scripts.doctor.do_deps(*unused_args)

Report on the runtime dependencies.

Parameters

unused_args – Ignored.

beancount.scripts.doctor.do_directories(filename, args)

Validate a directory hierarchy against a ledger’s account names.

Read a ledger’s list of account names and check that all the capitalized subdirectory names under the given roots match the account names.

Parameters
  • filename – A string, the Beancount input filename.

  • args – The rest of the arguments provided on the command-line, which in this case will be interpreted as the names of root directories to validate against the accounts in the given ledger.

beancount.scripts.doctor.do_display_context(filename, args)

Print out the precision inferred from the parsed numbers in the input file.

Parameters
  • filename – A string, which consists in the filename.

  • args – A tuple of the rest of arguments. We’re expecting the first argument to be an integer as a string.

beancount.scripts.doctor.do_dump_lexer(filename, unused_args)

Dump the lexer output for a Beancount syntax file.

Parameters

filename – A string, the Beancount input filename.

beancount.scripts.doctor.do_lex(filename, unused_args)

Dump the lexer output for a Beancount syntax file.

Parameters

filename – A string, the Beancount input filename.

beancount.scripts.doctor.do_linked(filename, args)

Print out a list of transactions linked to the one at the given line.

Parameters
  • filename – A string, which consists in the filename.

  • args – A tuple of the rest of arguments. We’re expecting the first argument to be an integer as a string.

beancount.scripts.doctor.do_list_options(*unused_args)

Print out a list of the available options.

Parameters

unused_args – Ignored.

beancount.scripts.doctor.do_missing_open(filename, args)

Print out Open directives that are missing for the given input file.

This can be useful during demos in order to quickly generate all the required Open directives without having to type them manually.

Parameters
  • filename – A string, which consists in the filename.

  • args – A tuple of the rest of arguments. We’re expecting the first argument to be an integer as a string.

beancount.scripts.doctor.do_parse(filename, unused_args)

Run the parser in debug mode.

Parameters

filename – A string, the Beancount input filename.

beancount.scripts.doctor.do_print_options(filename, *args)

Print out the actual options parsed from a file.

Parameters

unused_args – Ignored.

beancount.scripts.doctor.do_roundtrip(filename, unused_args)

Round-trip test on arbitrary Ledger.

Read a Ledger’s transactions, print them out, re-read them again and compare them. Both sets of parsed entries should be equal. Both printed files are output to disk, so you can also run diff on them yourself afterwards.

Parameters

filename – A string, the Beancount input filename.

beancount.scripts.doctor.do_validate_html(directory, args)

Validate all the HTML files under a directory hierachy.

Parameters
  • directory – A string, the root directory whose contents to validte.

  • args – A tuple of the rest of arguments.

beancount.scripts.doctor.get_commands()

Return a list of available commands in this file.

Returns

A list of pairs of (command-name string, docstring).

beancount.scripts.doctor.main()

beancount.scripts.example

Generate a decently-sized example history, based on some rules.

This script is used to generate some meaningful input to Beancount, input that looks as realistic as possible for a moderately complex mock individual. This can also be used as an input generator for a stress test for performance evaluation.

beancount.scripts.example.check_non_negative(entries, account, currency)

Check that the balance of the given account never goes negative.

Parameters
  • entries – A list of directives.

  • account – An account string, the account to check the balance for.

  • currency – A string, the currency to check minimums for.

Raises

AssertionError – if the balance goes negative.

beancount.scripts.example.compute_trip_dates(date_begin, date_end)

Generate dates at reasonable intervals for trips during the given time period.

Parameters
  • date_begin – The start date.

  • date_end – The end date.

Yields

Pairs of dates for the trips within the period.

beancount.scripts.example.contextualize_file(contents, employer)

Replace generic strings in the generated file with realistic strings.

Parameters

contents – A string, the generic file contents.

Returns

A string, the contextualized version.

beancount.scripts.example.date_iter(date_begin, date_end)

Generate a sequence of dates.

Parameters
  • date_begin – The start date.

  • date_end – The end date.

Yields

Instances of datetime.date.

beancount.scripts.example.date_random_seq(date_begin, date_end, days_min, days_max)

Generate a sequence of dates with some random increase in days.

Parameters
  • date_begin – The start date.

  • date_end – The end date.

  • days_min – The minimum number of days to advance on each iteration.

  • days_max – The maximum number of days to advance on each iteration.

Yields

Instances of datetime.date.

beancount.scripts.example.delay_dates(date_iter, delay_days_min, delay_days_max)

Delay the dates from the given iterator by some uniformly dranw number of days.

Parameters
  • date_iter – An iterator of datetime.date instances.

  • delay_days_min – The minimum amount of advance days for the transaction.

  • delay_days_max – The maximum amount of advance days for the transaction.

Yields

datetime.date instances.

beancount.scripts.example.generate_balance_checks(entries, account, date_iter)

Generate balance check entries to the given frequency.

Parameters
  • entries – A list of directives that contain all the transactions for the accounts.

  • account – The name of the account for which to generate.

  • date_iter – Iterator of dates. We generate balance checks at these dates.

Returns

A list of balance check entries.

beancount.scripts.example.generate_banking(entries, date_begin, date_end, amount_initial)

Generate a checking account opening.

Parameters
  • entries – A list of entries which affect this account.

  • date_begin – A date instance, the beginning date.

  • date_end – A date instance, the end date.

  • amount_initial – A Decimal instance, the amount to initialize the checking account with.

Returns

A list of directives.

beancount.scripts.example.generate_banking_expenses(date_begin, date_end, account, rent_amount)

Generate expenses paid out of a checking account, typically living expenses.

Parameters
  • date_begin – The start date.

  • date_end – The end date.

  • account – The checking account to generate expenses to.

  • rent_amount – The amount of rent.

Returns

A list of directives.

beancount.scripts.example.generate_clearing_entries(date_iter, payee, narration, entries, account_clear, account_from)

Generate entries to clear the value of an account.

Parameters
  • date_iter – An iterator of datetime.date instances.

  • payee – A string, the payee name to use on the transactions.

  • narration – A string, the narration to use on the transactions.

  • entries – A list of entries.

  • account_clear – The account to clear.

  • account_from – The source account to clear ‘account_clear’ from.

Returns

A list of directives.

beancount.scripts.example.generate_commodity_entries(date_birth)

Create a list of Commodity entries for all the currencies we’re using.

Parameters

date_birth – A datetime.date instance, the date of birth of the user.

Returns

A list of Commodity entries for all the commodities in use.

beancount.scripts.example.generate_employment_income(employer_name, employer_address, annual_salary, account_deposit, account_retirement, date_begin, date_end)

Generate bi-weekly entries for payroll salary income.

Parameters
  • employer_name – A string, the human-readable name of the employer.

  • employer_address – A string, the address of the employer.

  • annual_salary – A Decimal, the annual salary of the employee.

  • account_deposit – An account string, the account to deposit the salary to.

  • account_retirement – An account string, the account to deposit retirement contributions to.

  • date_begin – The start date.

  • date_end – The end date.

Returns

A list of directives, including open directives for the account.

beancount.scripts.example.generate_expense_accounts(date_birth)

Generate directives for expense accounts.

Parameters

date_birth – Birth date of the character.

Returns

A list of directives.

beancount.scripts.example.generate_open_entries(date, accounts, currency=None)

Generate a list of Open entries for the given accounts:

Parameters
  • date – A datetime.date instance for the open entries.

  • accounts – A list of account strings.

  • currency – An optional currency constraint.

Returns

A list of Open directives.

beancount.scripts.example.generate_outgoing_transfers(entries, account, account_out, transfer_minimum, transfer_threshold, transfer_increment)

Generate transfers of accumulated funds out of an account.

This monitors the balance of an account and when it is beyond a threshold, generate out transfers form that account to another account.

Parameters
  • entries – A list of existing entries that affect this account so far. The generated entries will also affect this account.

  • account – An account string, the account to monitor.

  • account_out – An account string, the savings account to make transfers to.

  • transfer_minimum – The minimum amount of funds to always leave in this account after a transfer.

  • transfer_threshold – The minimum amount of funds to be able to transfer out without breaking the minimum.

  • transfer_increment – A Decimal, the increment to round transfers to.

Returns

A list of new directives, the transfers to add to the given account.

beancount.scripts.example.generate_periodic_expenses(date_iter, payee, narration, account_from, account_to, amount_generator)

Generate periodic expense transactions.

Parameters
  • date_iter – An iterator for dates or datetimes.

  • payee – A string, the payee name to use on the transactions, or a set of such strings to randomly choose from

  • narration – A string, the narration to use on the transactions.

  • account_from – An account string the debited account.

  • account_to – An account string the credited account.

  • amount_generator – A callable object to generate variates.

Returns

A list of directives.

beancount.scripts.example.generate_prices(date_begin, date_end, currencies, cost_currency)

Generate weekly or monthyl price entries for the given currencies.

Parameters
  • date_begin – The start date.

  • date_end – The end date.

  • currencies – A list of currency strings to generate prices for.

  • cost_currency – A string, the cost currency.

Returns

A list of Price directives.

beancount.scripts.example.generate_regular_credit_expenses(date_birth, date_begin, date_end, account_credit, account_checking)

Generate expenses paid out of a credit card account, including payments to the credit card.

Parameters
  • date_birth – The user’s birth date.

  • date_begin – The start date.

  • date_end – The end date.

  • account_credit – The credit card account to generate expenses against.

  • account_checking – The checking account to generate payments from.

Returns

A list of directives.

beancount.scripts.example.generate_retirement_employer_match(entries, account_invest, account_income)

Generate employer matching contributions into a retirement account.

Parameters
  • entries – A list of directives that cover the retirement account.

  • account_invest – The name of the retirement cash account.

  • account_income – The name of the income account.

Returns

A list of new entries generated for employer contributions.

beancount.scripts.example.generate_retirement_investments(entries, account, commodities_items, price_map)

Invest money deposited to the given retirement account.

Parameters
  • entries – A list of directives

  • account – The root account for all retirement investment sub-accounts.

  • commodities_items – A list of (commodity, fraction to be invested in) items.

  • price_map – A dict of prices, as per beancount.core.prices.build_price_map().

Returns

A list of new directives for the given investments. This also generates account opening directives for the desired investment commodities.

beancount.scripts.example.generate_tax_accounts(year, date_max)

Generate accounts and contributino directives for a particular tax year.

Parameters
  • year – An integer, the year we’re to generate this for.

  • date_max – The maximum date to produce an entry for.

Returns

A list of directives.

beancount.scripts.example.generate_tax_preamble(date_birth)

Generate tax declarations not specific to any particular year.

Parameters

date_birth – A date instance, the birth date of the character.

Returns

A list of directives.

beancount.scripts.example.generate_taxable_investment(date_begin, date_end, entries, price_map, stocks)

Generate opening directives and transactions for an investment account.

Parameters
  • date_begin – A date instance, the beginning date.

  • date_end – A date instance, the end date.

  • entries – A list of entries that contains at least the transfers to the investment account’s cash account.

  • price_map – A dict of prices, as per beancount.core.prices.build_price_map().

  • stocks – A list of strings, the list of commodities to invest in.

Returns

A list of directives.

beancount.scripts.example.generate_trip_entries(date_begin, date_end, tag, config, trip_city, home_city, account_credit)

Generate more dense expenses for a trip.

Parameters
  • date_begin – A datetime.date instance, the beginning of the trip.

  • date_end – A datetime.date instance, the end of the trip.

  • tag – A string, the name of the tag.

  • config – A list of (payee name, account name, (mu, 3sigma)), where mu is the mean of the prices to generate and 3sigma is 3 times the standard deviation.

  • trip_city – A string, the capitalized name of the destination city.

  • home_city – A string, the name of the home city.

  • account_credit – A string, the name of the credit card account to pay the expenses from.

Returns

A list of entries for the trip, all tagged with the given tag.

beancount.scripts.example.get_minimum_balance(entries, account, currency)

Compute the minimum balance of the given account according to the entries history.

Parameters
  • entries – A list of directives.

  • account – An account string.

  • currency – A currency string, for which we want to compute the minimum.

Returns

A Decimal number, the minimum amount throughout the history of this account.

beancount.scripts.example.iter_dates_with_balance(date_begin, date_end, entries, accounts)

Iterate over dates, including the balances of the postings iterator.

Parameters
  • postings_iter – An iterator of postings as per postings_for().

  • date_begin – The start date.

  • date_end – The end date.

Yields
Pairs of (data, balances) objects, with

date: A datetime.date instance balances: An Inventory object, representing the current balance.

You can modify the inventory object to feed back changes in the balance.

beancount.scripts.example.iter_quarters(date_begin, date_end)

Iterate over all quarters between begin and end dates.

Parameters
  • date_begin – The start date.

  • date_end – The end date.

Yields

Instances of datetime.date at the beginning of the quarters. This will include the quarter of the beginning date and of the end date.

beancount.scripts.example.main()
beancount.scripts.example.merge_postings(entries, accounts)

Merge all the postings from the given account names.

Parameters
  • entries – A list of directives.

  • accounts – A list of account strings to get the balances for.

Yields

A list of TxnPosting’s for all the accounts, in sorted order.

beancount.scripts.example.parse(input_string, **replacements)

Parse some input string and assert no errors.

This parse function does not just create the object, it also triggers local interpolation to fill in the missing amounts.

Parameters
  • input_string – Beancount input text.

  • **replacements – A dict of keywords to replace to their values.

Returns

A list of directive objects.

beancount.scripts.example.postings_for(entries, accounts, before=False)

Realize the entries and get the list of postings for the given accounts.

All the non-Posting directives are already filtered out.

Parameters
  • entries – A list of directives.

  • accounts – A list of account strings to get the balances for.

  • before – A boolean, if true, yield the balance before the position is applied. The default is to yield the balance after applying the position.

Yields

Tuples of – posting: An instance of TxnPosting balances: A dict of Inventory balances for the given accounts _after_

applying the posting. These inventory objects can be mutated to adjust the balance due to generated transactions to be applied later.

beancount.scripts.example.price_series(start, mu, sigma)

Generate a price series based on a simple stochastic model.

Parameters
  • start – The beginning value.

  • mu – The per-step drift, in units of value.

  • sigma – Volatility of the changes.

Yields

Floats, at each step.

beancount.scripts.example.replace(string, replacements, strip=False)

Apply word-boundaried regular expression replacements to an indented string.

Parameters
  • string – Some input template string.

  • replacements – A dict of regexp to replacement value.

  • strip – A boolean, true if we should strip the input.

Returns

The input string with the replacements applied to it, with the indentation removed.

beancount.scripts.example.validate_output(contents, positive_accounts, currency)

Check that the output file validates.

Parameters
  • contents – A string, the output file.

  • positive_accounts – A list of strings, account names to check for non-negative balances.

  • currency – A string, the currency to check minimums for.

Raises

AssertionError – If the output does not validate.

beancount.scripts.example.write_example_file(date_birth, date_begin, date_end, reformat, file)

Generate the example file.

Parameters
  • date_birth – A datetime.date instance, the birth date of our character.

  • date_begin – A datetime.date instance, the beginning date at which to generate transactions.

  • date_end – A datetime.date instance, the end date at which to generate transactions.

  • reformat – A boolean, true if we should apply global reformatting to this file.

  • file – A file object, where to write out the output.

beancount.scripts.format

Align a beancount/ledger input file’s numbers.

This reformats at beancount or ledger input file so that the amounts in the postings are all aligned to the same column. The currency should match.

Note: this does not parse the Beancount ledger. It simply uses regular expressions and text manipulations to do its work.

beancount.scripts.format.align_beancount(contents, prefix_width=None, num_width=None, currency_column=None)

Reformat Beancount input to align all the numbers at the same column.

Parameters
  • contents – A string, Beancount input syntax to reformat.

  • prefix_width – An integer, the width in characters to render the account name to. If this is not specified, a good value is selected automatically from the contents of the file.

  • num_width – An integer, the width to render each number. If this is not specified, a good value is selected automatically from the contents of the file.

  • currency_column – An integer, the column at which to align the currencies. If given, this overrides the other options.

Returns

A string, reformatted Beancount input with all the number aligned. No other changes than whitespace changes should be present between that return value and the input contents.

beancount.scripts.format.compute_most_frequent(iterable)

Compute the frequencies of the given elements and return the most frequent.

Parameters

iterable – A collection of hashable elements.

Returns

The most frequent element. If there are no elements in the iterable, return None.

beancount.scripts.format.main()
beancount.scripts.format.normalize_indent_whitespace(match_pairs)

Normalize whitespace before lines that has some indent and an account name.

Parameters

match_pairs – A list of (prefix, number, rest) tuples.

Returns

Another list of (prefix, number, rest) tuples, where prefix may have been adjusted with a different whitespace prefi.

beancount.scripts.sql

Convert a Beancount ledger into an SQL database.

class beancount.scripts.sql.BalanceWriter
columns = '\n account VARCHAR\n amount_number DECIMAL(16,6)\n amount_currency CHARACTER(10)\n diff_number DECIMAL(16,6)\n diff_currency CHARACTER(10)\n '
get_detail(entry)

Provide data to store for details table.

Parameters

entry – An instance of the desired directive.

Returns

A tuple of the values corresponding to the columns declared in the ‘columns’ attribute.

type

alias of beancount.core.data.Balance

class beancount.scripts.sql.CloseWriter
columns = '\n account VARCHAR\n '
get_detail(entry)

Provide data to store for details table.

Parameters

entry – An instance of the desired directive.

Returns

A tuple of the values corresponding to the columns declared in the ‘columns’ attribute.

type

alias of beancount.core.data.Close

class beancount.scripts.sql.DirectiveWriter

A base class for writers of directives. This is used to factor out code for all the simple directives types (all types except Transaction).

columns = None
get_detail(entry)

Provide data to store for details table.

Parameters

entry – An instance of the desired directive.

Returns

A tuple of the values corresponding to the columns declared in the ‘columns’ attribute.

type = None
class beancount.scripts.sql.DocumentWriter
columns = '\n account VARCHAR\n filenam VARCHAR\n '
get_detail(entry)

Provide data to store for details table.

Parameters

entry – An instance of the desired directive.

Returns

A tuple of the values corresponding to the columns declared in the ‘columns’ attribute.

type

alias of beancount.core.data.Document

class beancount.scripts.sql.EventWriter
columns = '\n type VARCHAR\n description VARCHAR\n '
get_detail(entry)

Provide data to store for details table.

Parameters

entry – An instance of the desired directive.

Returns

A tuple of the values corresponding to the columns declared in the ‘columns’ attribute.

type

alias of beancount.core.data.Event

class beancount.scripts.sql.NoteWriter
columns = '\n account VARCHAR\n comment VARCHAR\n '
get_detail(entry)

Provide data to store for details table.

Parameters

entry – An instance of the desired directive.

Returns

A tuple of the values corresponding to the columns declared in the ‘columns’ attribute.

type

alias of beancount.core.data.Note

class beancount.scripts.sql.OpenWriter
columns = '\n account VARCHAR\n currencies VARCHAR\n '
get_detail(entry)

Provide data to store for details table.

Parameters

entry – An instance of the desired directive.

Returns

A tuple of the values corresponding to the columns declared in the ‘columns’ attribute.

type

alias of beancount.core.data.Open

class beancount.scripts.sql.PadWriter
columns = '\n account VARCHAR\n source_account VARCHAR\n '
get_detail(entry)

Provide data to store for details table.

Parameters

entry – An instance of the desired directive.

Returns

A tuple of the values corresponding to the columns declared in the ‘columns’ attribute.

type

alias of beancount.core.data.Pad

class beancount.scripts.sql.PriceWriter
columns = '\n currency CHARACTER(10)\n amount_number DECIMAL(16,6)\n amount_currency CHARACTER(10)\n '
get_detail(entry)

Provide data to store for details table.

Parameters

entry – An instance of the desired directive.

Returns

A tuple of the values corresponding to the columns declared in the ‘columns’ attribute.

type

alias of beancount.core.data.Price

class beancount.scripts.sql.QueryWriter
columns = '\n name VARCHAR\n query_string VARCHAR\n '
get_detail(entry)

Provide data to store for details table.

Parameters

entry – An instance of the desired directive.

Returns

A tuple of the values corresponding to the columns declared in the ‘columns’ attribute.

type

alias of beancount.core.data.Query

beancount.scripts.sql.adapt_decimal(number)

Adapt a Decimal instance to a string for creating queries.

Parameters

number – An instance of Decimal.

Returns

A string.

beancount.scripts.sql.convert_decimal(string)

Convert a Decimal string to a Decimal instance.

Parameters

string – A decimal number in a string.

Returns

An instance of Decimal.

beancount.scripts.sql.main()
beancount.scripts.sql.output_common(connection, unused_entries)

Create a table of common data for all entries.

Parameters
  • connection – A DBAPI-2.0 Connection object.

  • entries – A list of directives.

beancount.scripts.sql.output_transactions(connection, entries)

Create a table for transactions and fill in the data.

Parameters
  • connection – A DBAPI-2.0 Connection object.

  • entries – A list of directives.

beancount.scripts.sql.setup_decimal_support()

Setup sqlite3 to support conversions to/from Decimal numbers.

beancount.scripts.tutorial

Write output files for the tutorial commands.

beancount.scripts.tutorial.main()