### Create a Sample Beancount Ledger Source: https://beancount.github.io/docs/index.html/installing_beancount A simple Beancount ledger example used to test the successful installation of Beancount. Save this content to a file like 'tst.bean'. ```beancount 2024-01-01 open Assets:Bank 2024-01-01 open Equity:Opening-Balances 2024-01-01 * "Opening Balance" Assets:Bank 1000.00 USD Equity:Opening-Balances ``` -------------------------------- ### Check winflexbison Version on Windows Source: https://beancount.github.io/docs/index.html/installing_beancount After installing winflexbison and updating the system PATH, use this command in the command prompt to verify the installation by checking its version. A successful response confirms correct setup. ```Bash win_bison --version ``` -------------------------------- ### Install and Verify Beancount/Beanquery with uv Source: https://beancount.github.io/docs/index.html/installing_beancount These commands use the `uv` tool to install Beancount and beanquery, which are then added to the system PATH. The subsequent lines show how to run the installed binaries directly and their expected version output, confirming successful installation. ```Bash uv tool install beancount uv tool install beanquery beancount beanquery ``` -------------------------------- ### Test Beancount Installation with Beanquery Source: https://beancount.github.io/docs/index.html/installing_beancount Commands to run the bean-query tool against a sample Beancount ledger file (e.g., 'tst.bean') to confirm successful installation and functionality. ```bash bean-query tst.bean ``` ```bash python -m beanquery tst.bean ``` -------------------------------- ### Verify pipx Installed Packages Source: https://beancount.github.io/docs/index.html/installing_beancount Lists all packages installed via pipx to confirm the successful installation of Beancount and its associated executables. ```Python pipx list ``` -------------------------------- ### Clone Beancount Repository Source: https://beancount.github.io/docs/index.html/installing_beancount These commands clone the Beancount source code repository from GitHub and navigate into the newly created directory. This is the first step to installing Beancount from source. ```Bash git clone https://github.com/beancount/beancount.git cd beancount ``` -------------------------------- ### Install Beancount from Git Repository using pip Source: https://beancount.github.io/docs/index.html/installing_beancount Installs Beancount directly from its GitHub source code repository using pip, allowing users to get the very latest development version of the stable branch. ```Python sudo -H python3 -m pip install git+https://github.com/beancount/beancount#egg=beancount ``` -------------------------------- ### Install Beancount v3 Standalone on Windows Source: https://beancount.github.io/docs/index.html/installing_beancount Alternative commands to install Beancount v3 directly, without Beanquery, for cases where a standalone installation is preferred. ```bash pip install beancount ``` ```bash python -m pip install beancount ``` -------------------------------- ### Install Beancount from Local Source Directory Source: https://beancount.github.io/docs/index.html/installing_beancount Installs Beancount and its dependencies from the current local source directory using pip, typically after cloning the repository, to build and install the project. ```Python sudo -H python3 -m pip install . ``` -------------------------------- ### Clone Beancount Source Repository Source: https://beancount.github.io/docs/index.html/installing_beancount Provides the official GitHub repository URL for Beancount and the Git command to clone the source code onto a local machine. ```Git git clone https://github.com/beancount/beancount ``` -------------------------------- ### Install Beancount using pipx Source: https://beancount.github.io/docs/index.html/installing_beancount Installs Beancount and its dependencies into an isolated virtual environment using pipx, a recommended tool for installing Python applications. ```Python pipx install beancount ``` -------------------------------- ### Install Beancount for Development (setuptools) Source: https://beancount.github.io/docs/index.html/installing_beancount Uses the setuptools "develop" command to install Beancount in development mode, allowing in-place execution of the source code. This modifies a .pth file in the Python installation to point to the cloned source path. ```Python sudo python3 setup.py develop ``` -------------------------------- ### Run Beancount Unit Tests Source: https://beancount.github.io/docs/index.html/installing_beancount These commands navigate into the Beancount directory and then execute the unit tests using pytest. This step verifies the functionality of the Beancount installation, though some tests may fail on Windows due to POSIX assumptions. ```Bash cd beancount python -m pytest ``` -------------------------------- ### Generate and Verify Beancount Example File Source: https://beancount.github.io/docs/index.html/tutorial_example Begin by generating a default example Beancount file. After creation, it's crucial to verify that the file loads without any errors using `bean-check` to ensure its integrity before proceeding with report generation. ```Shell bean-example > example.beancount ``` ```Shell bean-check example.beancount ``` -------------------------------- ### Build Beancount from Source using Make Source: https://beancount.github.io/docs/index.html/installing_beancount Builds Beancount from its source code using the 'make' command, which requires 'meson' and 'ninja' to be installed. This is an alternative build method for local development. ```Makefile make build ``` -------------------------------- ### Install Beancount v2 on Windows Source: https://beancount.github.io/docs/index.html/installing_beancount Commands to install the last version of Beancount v2, specifying the version constraint to prevent upgrading to v3. ```bash pip install "beancount<3" ``` ```bash python -m pip install "beancount<3" ``` -------------------------------- ### Install Beancount v3 via Beanquery on Windows Source: https://beancount.github.io/docs/index.html/installing_beancount Instructions to install Beancount v3 by installing Beanquery, which includes Beancount as a dependency. This is the recommended method for v3 as custom reports and bean-web are discontinued. ```bash pip install beanquery ``` ```bash python -m pip install beanquery ``` ```bash uv tool install beanquery ``` -------------------------------- ### List Beancount Dependencies for Troubleshooting Source: https://beancount.github.io/docs/index.html/installing_beancount This command runs a Beancount script that lists all installed dependencies and their versions. The output is useful for including in bug reports to help diagnose problems with the Beancount installation. ```Python python3 -m beancount.scripts.deps ``` -------------------------------- ### Install Beancount using WSL (Ubuntu) Source: https://beancount.github.io/docs/index.html/installing_beancount These commands are for installing Beancount within the Windows Subsystem for Linux (WSL), specifically on an Ubuntu environment. They install pip3, a decimal library, and then Beancount itself using sudo for system-wide installation. ```Bash sudo apt-get install python3-pip sudo pip3 install m3-cdecimal sudo pip3 install beancount --pre ``` -------------------------------- ### Verify Beancount Installation with bean-check Source: https://beancount.github.io/docs/index.html/installing_beancount This command demonstrates how to use bean-check, a Beancount utility, to verify the installation. The code shows the expected output when the command is run without the required filename argument, indicating the binary is accessible. ```Bash $ bean-check usage: bean-check [-h] [-v] filename bean-check: error: the following arguments are required: filename ``` -------------------------------- ### Clone Beancount Source for Local Build Source: https://beancount.github.io/docs/index.html/installing_beancount Clones the Beancount source code repository from GitHub as the initial step for building and installing Beancount directly from source, providing access to the latest stable branch. ```Git git clone https://github.com/beancount/beancount ``` -------------------------------- ### View Beancount Example Generator Options Source: https://beancount.github.io/docs/index.html/tutorial_example This command displays the available options for the `bean-example` script. Users can consult these options to customize the data generation process, such as fixing the random generator's seed for reproducible outputs. ```Shell bean-example --help ``` -------------------------------- ### Clone Beancount Repository Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Clone the Beancount v3 source code repository from GitHub to your local machine. This is the first step for development setup using Meson. ```bash git clone https://github.com/beancount/beancount.git ``` -------------------------------- ### Install Pytest for Beancount Testing Source: https://beancount.github.io/docs/index.html/installing_beancount This command installs pytest, a popular Python testing framework, which is necessary to run the unit tests for Beancount. It ensures the testing environment is set up correctly. ```Python python -m pip install pytest ``` -------------------------------- ### Install Beancount using pip (Not Recommended) Source: https://beancount.github.io/docs/index.html/installing_beancount Installs Beancount from the PyPI repository using pip. This method is generally not recommended due to potential system library conflicts and installs the latest PyPI release, which might not be the absolute latest source version. ```Python sudo -H python3 -m pip install beancount ``` -------------------------------- ### Install Python Build Utilities Source: https://beancount.github.io/docs/index.html/installing_beancount This command installs essential Python packages like meson-python, meson, and ninja, which are required for building Beancount from source. It uses pip, Python's package installer. ```Python python -m pip install meson-python meson ninja ``` -------------------------------- ### Beancount Example Directives: Open, Note, Balance Source: https://beancount.github.io/docs/index.html/beancount_language_syntax Provides concrete examples of common Beancount directives, including opening an account, adding a note, and asserting a balance. These examples demonstrate the practical application of the general directive syntax and the declarative nature of the language. ```Beancount 2014-02-03 open Assets:US:BofA:Checking 2014-04-10 note Assets:US:BofA:Checking "Called to confirm wire transfer." 2014-05-02 balance Assets:US:BofA:Checking 154.20 USD ``` -------------------------------- ### API Reference: TmpFilesTestBase.setUp Source: https://beancount.github.io/docs/index.html/api_reference/beancount.utils API documentation for the `setUp` method, a hook method for setting up the test fixture before exercising it. ```APIDOC beancount.utils.test_utils.TmpFilesTestBase.setUp(self) Description: Hook method for setting up the test fixture before exercising it. ``` -------------------------------- ### Generate Beancount Example File Source: https://beancount.github.io/docs/index.html/tutorial_example This command generates several years of realistic historical financial entries for a fictional user, redirecting the output to a Beancount file named `example.beancount`. It's useful for experimenting with Beancount, generating reports, and stress testing the software. ```Shell bean-example > example.beancount ``` -------------------------------- ### List detailed Beancount holdings Source: https://beancount.github.io/docs/index.html/tutorial_example This command generates a detailed list of all financial holdings recorded in the `example.beancount` file. It provides a comprehensive overview of all assets and their quantities. ```shell bean-report example.beancount holdings ``` -------------------------------- ### Example Invocation of Beancount bean-extract Source: https://beancount.github.io/docs/index.html/importing_external_data An example demonstrating how to run the `bean-extract` tool with a specific configuration file (e.g., `blais.config`) and a downloads directory (e.g., `~/Downloads`). ```shell bean-extract blais.config ~/Downloads ``` -------------------------------- ### Install Meson Build System Dependencies Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Install the necessary Python packages for building Beancount v3 with Meson, including `meson-python`, `meson`, and `ninja`. ```bash python -m pip install meson-python meson ninja ``` -------------------------------- ### List all Beancount accounts Source: https://beancount.github.io/docs/index.html/tutorial_example This command lists all accounts defined within the `example.beancount` file. It provides a comprehensive overview of the chart of accounts, including active and closed accounts. ```shell bean-report example.beancount accounts ``` -------------------------------- ### Configure Environment Variables for Beancount Development Source: https://beancount.github.io/docs/index.html/installing_beancount Sets the PATH and PYTHONPATH environment variables to include the locally built Beancount binary and library directories, enabling the system to locate and use the development installation. ```Shell export PATH=$PATH:/path/to/beancount/bin export PYTHONPATH=$PYTHONPATH:/path/to/beancount ``` -------------------------------- ### Install Pytest for Beancount Development Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Install the `pytest` framework, which is used for running unit tests in Beancount v3. ```bash python -m pip install pytest ``` -------------------------------- ### Example Invocation of Beancount bean-file with Output Directory Source: https://beancount.github.io/docs/index.html/importing_external_data An example showing how to use `bean-file` to move downloaded files to a specified output directory (e.g., `~/accounting/documents`) for preservation and organization. ```shell bean-file -o ~/accounting/documents blais.config ~/Downloads ``` -------------------------------- ### Install Beancount in Editable Mode with Meson Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Install Beancount v3 in editable mode using `pip` and `meson-python`. The `--no-build-isolation` option is often required for this setup, allowing direct development without reinstallation. ```bash python -m pip install --no-build-isolation --editable . ``` -------------------------------- ### Generate a basic Beancount balance sheet Source: https://beancount.github.io/docs/index.html/tutorial_example This command generates a balance sheet from the `example.beancount` file. The output is currently only supported in HTML format, and filtering entries from the command-line is not supported. ```shell bean-report example.beancount balsheet ``` -------------------------------- ### Install Beancount from Source in Editable Mode Source: https://beancount.github.io/docs/index.html/installing_beancount This command installs Beancount directly from its source directory in editable mode, allowing for local modifications to the package. The --no-build-isolation flag is used to prevent issues with build dependencies. ```Python python -m pip install --no-build-isolation -e . ``` -------------------------------- ### List Beancount events Source: https://beancount.github.io/docs/index.html/tutorial_example This command lists all events recorded in the `example.beancount` file. Events can include various significant dates or occurrences, such as opening accounts or major financial milestones. ```shell bean-report example.beancount events ``` -------------------------------- ### Example Output of Account Journal with Balance Source: https://beancount.github.io/docs/index.html/beancount_query_language Provides an example of the command-line execution and the resulting tabular output when querying for an account journal including the cumulative balance column. ```Shell $ bean-query $T "select date, account, position, balance where account ~ 'Expenses:Food:Restaurant';" date account position balance ---------- ------------------------ --------- ---------- 2012-01-02 Expenses:Food:Restaurant 31.02 USD 31.02 USD 2012-01-04 Expenses:Food:Restaurant 25.33 USD 56.35 USD 2012-01-08 Expenses:Food:Restaurant 67.88 USD 124.23 USD 2012-01-09 Expenses:Food:Restaurant 35.28 USD 159.51 USD 2012-01-14 Expenses:Food:Restaurant 25.84 USD 185.35 USD 2012-01-17 Expenses:Food:Restaurant 36.73 USD 222.08 USD 2012-01-21 Expenses:Food:Restaurant 28.11 USD 250.19 USD 2012-01-22 Expenses:Food:Restaurant 21.12 USD 271.31 USD ``` -------------------------------- ### Install Pytest Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Installs the pytest framework, a popular tool for running Python test suites, which is used for Beancount's tests. ```python (venv) C:\_code\t\beancount>py -m pip install pytest ``` -------------------------------- ### API Reference: write_example_file Function Source: https://beancount.github.io/docs/index.html/api_reference/beancount.scripts Documents the `write_example_file` function, detailing its purpose, required parameters, and their expected types for generating an example Beancount ledger. ```APIDOC beancount.scripts.example.write_example_file(date_birth, date_begin, date_end, reformat, file) Description: 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 Plugin Invocation Order Example Source: https://beancount.github.io/docs/index.html/api_reference/beancount.plugins Provides an example of how to correctly invoke Beancount plugins in a configuration file, specifically demonstrating the recommended order for `close_tree` to be placed after plugins like `auto_accounts` that might generate `open` directives. ```Beancount plugin "beancount.plugins.auto_accounts" plugin "beancount.plugins.close_tree" ``` -------------------------------- ### Install Beancount Build Dependencies Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Installs essential Python packages like meson-python, meson, and ninja, which are required for building Beancount from source. ```python (venv) C:\_code\t\beancount>py -m pip install meson-python meson ninja ``` -------------------------------- ### Run Beancount Web Interface Source: https://beancount.github.io/docs/index.html/getting_started_with_beancount Demonstrates how to start the Beancount web interface using the `bean-web` command, pointing it to a Beancount input file. Users can then access reports via a web browser at `http://localhost:8080`. ```Shell bean-web /path/to/your/file.beancount ``` -------------------------------- ### Clone Beancount Repository Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Clones the Beancount source code from GitHub and navigates into the project directory. ```shell git clone https://github.com/beancount/beancount.git cd beancount ``` -------------------------------- ### Build All Beancount Binaries with Bazel Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Command to build all executable binaries for Beancount v3 using the Bazel build system. This compiles the entire project. ```bash bazel build //bin:all ``` -------------------------------- ### Example Beancount Account Names for Common Categories Source: https://beancount.github.io/docs/index.html/command_line_accounting_cookbook Provides concrete examples of Beancount account names for Assets, Liabilities, and Income. These examples demonstrate the `Type:Country:Institution:Account` structure with comments explaining the purpose of each account. ```Beancount Assets:US:BofA:Savings ; Bank of America “Savings” account Assets:CA:RBC:Checking ; Royal Bank of Canada “Checking” account Liabilities:US:Amex:Platinum ; American Express Platinum credit card Liabilities:CA:RBC:Mortgage ; Mortgage loan account at RBC Income:US:ETrade:Interest ; Interest payments in E*Trade account Income:US:Acme:Salary ; Salary income from ACME corp. ``` -------------------------------- ### Example Beancount Transactions for Initial Stock Purchases Source: https://beancount.github.io/docs/index.html/beancount_language_syntax Illustrates how to record initial purchases of shares (IVV) in Beancount, showing different cost basis and optional labels for tracking lots. ```Beancount 2014-02-11 * "Bought shares of S&P 500" Assets:ETrade:IVV 20 IVV {183.07 USD, "ref-001"} … 2014-03-22 * "Bought shares of S&P 500" Assets:ETrade:IVV 15 IVV {187.12 USD} … ``` -------------------------------- ### Activate Python Virtual Environment Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Activates the Python virtual environment within the Beancount project, preparing the shell for installing Python packages. ```cmd C:\_code\t\beancount>venv\Scripts\Activate (venv) C:\_code\t\beancount> ``` -------------------------------- ### Inquiring Available Beancount Reports Source: https://beancount.github.io/docs/index.html/running_beancount_and_generating_reports Demonstrates how to use the `bean-report` command-line tool to list all available report types supported by the installed Beancount version. ```Shell bean-report --help-reports ``` -------------------------------- ### Beancount: Realistic Account Naming Examples Source: https://beancount.github.io/docs/index.html/beancount_language_syntax This snippet provides examples of realistic and valid account names in Beancount. It demonstrates the colon-separated, capitalized word structure and how different account types are used to create specific account paths. ```Beancount Assets:US:BofA:Checking Liabilities:CA:RBC:CreditCard Equity:Retained-Earnings Income:US:Acme:Salary Expenses:Food:Groceries ``` -------------------------------- ### Beancount Transaction Syntax Example Source: https://beancount.github.io/docs/index.html/the_double_entry_counting_method This snippet provides an example of a Beancount transaction entry, demonstrating the syntax for recording a double-entry transaction with a date, payee, narration, and two balanced postings to different accounts. ```Beancount 2016-12-06 * "Biang!" "Dinner" Liabilities:CreditCard -47.23 USD Expenses:Restaurants ``` -------------------------------- ### Navigate to Beancount Project Directory Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Changes the current directory to the Beancount project folder after opening the x64 Native Tools Command Prompt for Visual Studio. ```cmd C:\Program Files\Microsoft Visual Studio\2022\Community>cd C:\_code\t\beancount C:\_code\t\beancount> ``` -------------------------------- ### Simplified Beancount Account Naming Examples Source: https://beancount.github.io/docs/index.html/the_double_entry_counting_method Examples illustrating a simpler account naming convention in Beancount, where account names are kept concise. This approach relies on other metadata like payees or tags for further grouping and analysis, rather than embedding all details in the account name itself. ```Beancount Expenses:Phone Assets:AccountsReceivable ``` -------------------------------- ### Beancount: Inventory for FIFO Booking Example Source: https://beancount.github.io/docs/index.html/how_inventories_work Provides an example inventory state used to illustrate how the FIFO booking method handles reductions when multiple lots match. ```plaintext units ccy cost cost-ccy lot-date label 25 HOOL {23.00 USD, 2015-04-01, "first-lot"} 35 HOOL {27.00 USD, 2015-05-01, None} ``` -------------------------------- ### Example Beancount Price Source String for Google Finance Source: https://beancount.github.io/docs/index.html/fetching_prices_in_beancount Provides an example of a price source string for fetching Apple stock prices (AAPL) quoted in USD from Google Finance using the `beancount.prices.sources.google` module. ```Beancount USD:beancount.prices.sources.google/NASDAQ:AAPL ``` -------------------------------- ### Beancount Full Booking Algorithm and Interpolation Examples Source: https://beancount.github.io/docs/index.html/api_reference/beancount.parser This section describes the full booking implementation, highlighting the interplay between interpolation and booking in Beancount. It provides examples of Beancount transactions to illustrate how numbers filled by interpolation can affect booking, and vice-versa. It outlines a three-step algorithm for processing inventory reductions first, then computing interpolations, and finally converting interpolated cost specifications. ```Beancount 2015-09-30 * Assets:Investments -10 HOOL {USD} Assets:Cash 1000 USD Income:Gains -200 USD ``` ```Beancount 2015-09-30 * Assets:Investments -10 HOOL {USD} Assets:Cash 1000 USD Income:Gains ``` ```Beancount 2015-09-30 * Assets:Investments -10 HOOL {100.00 # USD} Expenses:Commission 9.95 USD Assets:Cash 990.05 USD ``` -------------------------------- ### Example Downloaded OFX File Path Source: https://beancount.github.io/docs/index.html/ledgerhub_design_doc This snippet shows a typical path for a downloaded OFX (Open Financial Exchange) file before it is processed and filed by the Beancount system. ```plaintext ~/Downloads/ofx32755.qbo ``` -------------------------------- ### Example Beancount Balance Report Output Source: https://beancount.github.io/docs/index.html/running_beancount_and_generating_reports Illustrates the typical structure and content of a Beancount balance report, showing hierarchical accounts with their associated balances and currencies. ```Text |-- Assets | `-- US | |-- BofA | | `-- Checking 596.05 USD | |-- ETrade | | |-- Cash 5,120.50 USD | | |-- GLD 70.00 GLD | | |-- ITOT 17.00 ITOT | | |-- VEA 36.00 VEA | | `-- VHT 294.00 VHT | |-- Federal | | `-- PreTax401k | |-- Hoogle | | `-- Vacation 337.26 VACHR | `-- Vanguard ... ``` -------------------------------- ### Calculate Beancount net worth Source: https://beancount.github.io/docs/index.html/tutorial_example This command calculates the total net worth from the `example.beancount` file. It aggregates all holdings and liabilities to provide a single, comprehensive net worth figure. ```shell bean-report example.beancount networth ``` -------------------------------- ### Open a Beancount Account Source: https://beancount.github.io/docs/index.html/getting_started_with_beancount Demonstrates how to open a new account in Beancount with an approximate date and currency. This is the first step before establishing an initial balance. ```Beancount 2000-05-28 open Assets:CA:BofA:Checking USD ``` -------------------------------- ### Generate Various Beancount Reports and View Help Options Source: https://beancount.github.io/docs/index.html/tutorial_example This section demonstrates how to generate different types of reports using the `bean-report` script. It also shows how to list available reports, view report-specific options, global script options, and supported output formats. ```Shell bean-report example.beancount balances ``` ```Shell bean-report --help-reports ``` ```Shell bean-report example.beancount balances --help ``` ```Shell bean-report --help ``` ```Shell bean-report --help-formats ``` -------------------------------- ### Minimal Beancount Plugin Example in Python Source: https://beancount.github.io/docs/index.html/beancount_scripting_plugins This Python code provides a minimal example of a Beancount plugin. It defines the '__plugins__' attribute as a list containing the 'wash_sales' function. The 'wash_sales' function accepts 'entries' and 'options_map', iterates through the entries, and returns the original entries along with an empty list of errors, serving as a basic template for custom plugin development. ```Python __plugins__ = ['wash_sales'] def wash_sales(entries, options_map): errors = [] for entry in entries: print(type(entry)) return entries, errors ``` -------------------------------- ### Aggregate Beancount holdings by account Source: https://beancount.github.io/docs/index.html/tutorial_example This command aggregates the detailed holdings by their respective accounts. The `--by=account` option groups holdings, providing a summarized view of assets per account. ```shell bean-report example.beancount holdings --by=account ``` -------------------------------- ### Example Inventory Balance for FLATTEN Option Source: https://beancount.github.io/docs/index.html/beancount_query_language This code snippet shows an example of an inventory balance with multiple lots, which is used to demonstrate the effect of the FLATTEN query option. Each line represents a separate lot of the 'AAPL' commodity at a specific cost. ```Beancount Data 3 AAPL {102.34 USD} 4 AAPL {104.53 USD} 5 AAPL {106.23 USD} ``` -------------------------------- ### Current Importer File Structure Example Source: https://beancount.github.io/docs/index.html/beangulp This snippet illustrates the current two-file structure for importers, consisting of an implementation file and a separate test file. ```Python soandso_bank.py soandso_bank_test.py ``` -------------------------------- ### View Beancount bean-check Error Output Example Source: https://beancount.github.io/docs/index.html/running_beancount_and_generating_reports This example demonstrates the format of error messages produced by `bean-check` when issues like unbalanced transactions are detected. The output includes the file path, line number, error description, and the relevant transaction details, designed for easy integration with text editors like Emacs. ```Shell /home/user/myledger.beancount:44381: Transaction does not balance: 34.46 USD 2014-07-12 * "Black Iron Burger" "" Expenses:Food:Restaurant 17.23 USD Assets:Cash 17.23 USD ``` -------------------------------- ### Generate Beancount balance sheet to HTML file Source: https://beancount.github.io/docs/index.html/tutorial_example This command generates a balance sheet from `example.beancount` and redirects the HTML output to a specified file, `/tmp/balsheet.html`. Users can then open this file in a browser for viewing. ```shell bean-report example.beancount balsheet > /tmp/balsheet.html ``` -------------------------------- ### Convert Beancount File to Ledger Format Source: https://beancount.github.io/docs/index.html/tutorial_example This command converts a Beancount file (e.g., `example.beancount`) into Ledger syntax, saving the output to `example.lgr`. This conversion facilitates comparison with Ledger reports and integration with Ledger-based workflows. ```Shell bean-report example.beancount ledger > example.lgr ``` -------------------------------- ### Basic Beancount Pad Directive Example Source: https://beancount.github.io/docs/index.html/beancount_language_syntax Illustrates the fundamental structure of a 'pad' directive in Beancount, showing the date, 'pad' keyword, account to credit, and the equity account for the other leg. ```Beancount 2014-06-01 pad Assets:BofA:Checking Equity:Opening-Balances ``` -------------------------------- ### Get Account Name Without Root (Python) Source: https://beancount.github.io/docs/index.html/api_reference/beancount.core Extracts the account name without its root component. For example, 'Assets:BofA:Checking' will produce 'BofA:Checking'. This is useful for getting the relative path within an account hierarchy. ```APIDOC beancount.core.account.sans_root(account_name: str) Parameters: account_name (str): A string, the name of the account whose leaf name to return. Returns: str: A string, the name of the non-root portion of this account name. ``` ```Python def sans_root(account_name: Account)-> Account: """Get the name of the account without the root. For example, an input of 'Assets:BofA:Checking' will produce 'BofA:Checking'. Args: account_name: A string, the name of the account whose leaf name to return. Returns: A string, the name of the non-root portion of this account name. """ assert isinstance(account_name, str) components = account_name.split(sep)[1:] return join(*components) if account_name else None ``` -------------------------------- ### Show Beancount posting statistics Source: https://beancount.github.io/docs/index.html/tutorial_example This command provides statistics on the number of postings by type within the `example.beancount` file. It offers insights into the volume and nature of transactions, such as how many credit or debit postings exist. ```shell bean-report example.beancount stats-postings ``` -------------------------------- ### Create OptDesc Instance Source: https://beancount.github.io/docs/index.html/api_reference/beancount.parser Documents the `__new__` static method for `OptDesc`, used to create new instances with specified name, default value, example, converter, deprecation status, and alias. ```APIDOC beancount.parser.options.OptDesc.__new__(_cls, name, default_value, example_value, converter, deprecated, alias) ``` -------------------------------- ### Show Beancount directive statistics Source: https://beancount.github.io/docs/index.html/tutorial_example This command provides statistics on the number of directives by type within the `example.beancount` file. It helps in understanding the composition of the ledger, such as how many transactions, balances, or prices are recorded. ```shell bean-report example.beancount stats-directives ``` -------------------------------- ### Run Beancount Tests with Pytest Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Execute all Beancount v3 tests using `pytest`. The `--import-mode=importlib` option ensures proper module import behavior during testing. ```bash pytest --import-mode=importlib beancount/ ``` -------------------------------- ### Python: Implementation of write_example_file Source: https://beancount.github.io/docs/index.html/api_reference/beancount.scripts Illustrates the internal logic for generating an example Beancount file, including the creation of various financial entries like income, expenses, and credit card transactions, and managing account names and commodities. ```python def write_example_file(date_birth, date_begin, date_end, reformat, file): """Generate the example file. Args: 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. """ # The following code entirely writes out the output to generic names, such # as "Employer1", "Bank1", and "CCY" (for principal currency). Those names # are purposely chosen to be unique, and only near the very end do we make # renamings to more specific and realistic names. # Name of the checking account. account_opening = 'Equity:Opening-Balances' account_payable = 'Liabilities:AccountsPayable' account_checking = 'Assets:CC:Bank1:Checking' account_credit = 'Liabilities:CC:CreditCard1' account_retirement = 'Assets:CC:Retirement' account_investing = 'Assets:CC:Investment:Cash' # Commodities. commodity_entries = generate_commodity_entries(date_birth) # Estimate the rent. rent_amount = round_to(ANNUAL_SALARY / RENT_DIVISOR, RENT_INCREMENT) # Get a random employer. employer_name, employer_address = random.choice(EMPLOYERS) logging.info("Generating Salary Employment Income") income_entries = generate_employment_income(employer_name, employer_address, ANNUAL_SALARY, account_checking, join(account_retirement, 'Cash'), date_begin, date_end) logging.info("Generating Expenses from Banking Accounts") banking_expenses = generate_banking_expenses(date_begin, date_end, account_checking, rent_amount) logging.info("Generating Regular Expenses via Credit Card") credit_regular_entries = generate_regular_credit_expenses( date_birth, date_begin, date_end, account_credit, account_checking) logging.info("Generating Credit Card Expenses for Trips") trip_entries = [] destinations = sorted(TRIP_DESTINATIONS.items()) destinations.extend(destinations) random.shuffle(destinations) for (date_trip_begin, date_trip_end), (destination_name, config) in zip( compute_trip_dates(date_begin, date_end), destinations): # Compute a suitable tag. tag = 'trip-{}-{}'.format(destination_name.lower().replace(' ', '-'), date_trip_begin.year) #logging.info("%s -- %s %s", tag, date_trip_begin, date_trip_end) # Remove regular entries during this trip. credit_regular_entries = [entry for entry in credit_regular_entries if not(date_trip_begin <= entry.date < date_trip_end)] # Generate entries for the trip. this_trip_entries = generate_trip_entries( date_trip_begin, date_trip_end, tag, config, destination_name.replace('-', ' ').title(), HOME_NAME, account_credit) trip_entries.extend(this_trip_entries) logging.info("Generating Credit Card Payment Entries") credit_payments = generate_clearing_entries( delay_dates(rrule.rrule(rrule.MONTHLY, dtstart=date_begin, until=date_end, bymonthday=7), 0, 4), "CreditCard1", "Paying off credit card", credit_regular_entries, account_credit, account_checking) credit_entries = credit_regular_entries + trip_entries + credit_payments logging.info("Generating Tax Filings and Payments") tax_preamble = generate_tax_preamble(date_birth) # Figure out all the years we need tax accounts for. years = set() for account_name in getters.get_accounts(income_entries): match = re.match(r'Expenses:Taxes:Y(\d\d\d\d)', account_name) if match: years.add(int(match.group(1))) ``` -------------------------------- ### Assert Account Balance in Beancount Source: https://beancount.github.io/docs/index.html/sharing_expenses_with_beancount This Beancount example shows how to use a balance assertion to verify the remaining funds in an asset account at a specific point in time, such as before leaving an airport. This helps in triangulating forgotten expenses. ```Beancount 2015-03-04 balance Assets:Cash:Pesos 65 MXN ``` -------------------------------- ### Aggregate Beancount holdings by commodity Source: https://beancount.github.io/docs/index.html/tutorial_example This command aggregates holdings based on the commodity type. The `--by=commodity` option provides a summary of total holdings for each distinct commodity recorded in the ledger. ```shell bean-report example.beancount holdings --by=commodity ``` -------------------------------- ### Book Individual Expenses with Shared Money in Beancount Source: https://beancount.github.io/docs/index.html/sharing_expenses_with_beancount This Beancount example demonstrates how to record individual expenses, such as a marine park fee, paid from shared money. It shows booking separate amounts to different expense accounts for each participant, which will be reconciled later. ```Beancount 2015-02-25 * "Marine Park (3 days Martin, 1 day Caroline)" Expenses:Scuba:ParkFees:Martin 7.50 USD Expenses:Scuba:ParkFees:Caroline 2.50 USD Assets:Cash:Martin ``` -------------------------------- ### Beancount Example: Paystub Configuration with Funds Source: https://beancount.github.io/docs/index.html/fund_accounting_with_beancount This Beancount code snippet demonstrates the setup of accounts and transactions for a pay stub using the 'Funds' feature. It includes opening various asset, expense, and income accounts, specifically defining FSA and Retirement403b fund accounts. The example illustrates how to record gross income, deductions for taxes, health insurance, FSA, and 403b contributions, and how to handle direct and reimbursed medical expenses within the fund structure. It highlights the balancing of Assets and Liabilities within a separate Fund. ```Beancount option "title" "Paystub - no Funds" 2014-07-15 open Assets:Bank:Checking 2014-07-15 open Assets:CreditUnion:Saving 2014-07-15 open Assets:FedIncTaxDeposits 2014-07-15 open Expenses:OASI 2014-07-15 open Expenses:Medicare 2014-07-15 open Expenses:MedicalAid 2014-07-15 open Expenses:SalReduction:HealthInsurance 2014-07-15 open Expenses:SalReduction:FSA 2014-07-15 open Expenses:SalReduction:R-403b 2014-07-15 open Income:Gross:Emp1 2014-07-15 open Income:EmplContrib:Emp1:Retirement 2014-01-01 open FSA:Assets ; FSA fund accounts 2014-01-01 open FSA:Income:Contributions 2014-01-01 open FSA:Expenses:Medical 2014-01-01 open FSA:Expenses:ReimburseMedical 2014-01-01 open FSA:Liabilities 2014-07-15 open Retirement403b:Assets:CREF ; Retirement fund accounts 2014-07-15 open Retirement403b:Income:EmployeeContrib 2014-07-15 open Retirement403b:Income:EmployerContrib 2014-07-15 open Retirement403b:Income:EarningsGainsAndLosses ; This implements the same idea as above for the FSA, of balancing ; Assets and Liabilities at the opening, but now does it using a ; separate Fund. 2014-01-01 ! "Set up FSA for 2014" FSA:Assets 2000 USD FSA:Liabilities -2000 USD 2014-07-15 ! "Emp1 Paystub" Income:Gross:Emp1 -6000 USD Assets:Bank:Checking 3000 USD Assets:CreditUnion:Saving 1000 USD Assets:FedIncTaxDeposits 750 USD Expenses:OASI 375 USD Expenses:Medicare 100 USD Expenses:MedicalAid 10 USD Expenses:SalReduction:R-403b 600 USD Retirement403b:Income:EmployeeContrib -600 USD Retirement403b:Assets:CREF 600 USD Expenses:SalReduction:FSA 75 USD FSA:Income:Contributions -75 USD FSA:Liabilities Expenses:SalReduction:HealthInsurance Retirement403b:Income:EmployerContrib -600 USD Retirement403b:Assets:CREF 2014-01-01 open Expenses:Medical 2014-07-20 ! "Direct expense from FSA" FSA:Expenses:Medical 25 USD FSA:Assets 2014-07-20 ! "Medical expense from checking" Expenses:Medical 25 USD Assets:Bank:Checking 2014-07-20 ! "Medical expense reimbursed from FSA" Assets:Bank:Checking 25 USD Income:ReimburseMedical FSA:Assets -25 USD FSA:Expenses:ReimburseMedical ``` -------------------------------- ### Install Python Development Dependencies for Beancount v3 Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Installs the necessary Python packages required to run Beancount v3 programs. This step uses pip to install dependencies listed in the development requirements file. ```Python pip install –r requirements/dev.txt ``` -------------------------------- ### Run Beancount Tests Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Executes the Beancount test suite using pytest with the importlib mode. Note that some tests may fail on Windows due to known portability issues. ```python (venv) C:\_code\t\beancount>pytest --import-mode=importlib beancount ``` -------------------------------- ### Record Itemized Shared Bill in Beancount Source: https://beancount.github.io/docs/index.html/sharing_expenses_with_beancount This Beancount example illustrates how to translate a single itemized bill, like a dive shop charge, into a detailed transaction. It shows booking various rental gear and dive expenses to individual participant accounts, including taxes, from a single credit card payment. ```Beancount 2015-03-01 * "Scuba Club Cozumel" | "Dive shop bill" ^69b409189b37 Income:Martin:CreditCard -381.64 USD Expenses:Scuba:Martin 27 USD ;; Regulator w/ Gauge Expenses:Scuba:Caroline 9 USD ;; Regulator w/ Gauge Expenses:Scuba:Martin 27 USD ;; BCD Expenses:Scuba:Caroline 9 USD ;; BCD Expenses:Scuba:Martin 6 USD ;; Fins Expenses:Scuba:Martin 24 USD ;; Wetsuit Expenses:Scuba:Caroline 8 USD ;; Wetsuit Expenses:Scuba:Caroline 9 USD ;; Dive computer Expenses:Scuba:Martin 5 USD ;; U/W Light Expenses:Scuba:Caroline 70 USD ;; Dive trip (2 tank) Expenses:Scuba:Martin 45 USD ;; Wreck Dive w/ Lite Expenses:Scuba:Martin 45 USD ;; Afternoon dive Expenses:Scuba:Caroline 45 USD ;; Afternoon dive Expenses:Scuba:Martin 28.64 USD ;; Taxes Expenses:Scuba:Caroline 24.00 USD ;; Taxes ``` -------------------------------- ### Beancount Paystub Setup Without Funds Source: https://beancount.github.io/docs/index.html/fund_accounting_with_beancount This Beancount example demonstrates setting up a pay stub with health insurance, FSA, and 403b contributions without using explicit 'Funds' accounts. It highlights the challenge of accurately tracking contributions and taxable income when gross income is directly distributed to deferred accounts, rather than recognizing contributions as salary reductions. ```Beancount option “title” “Paystub - no funds” 2014-07-15 open Assets:Bank:Checking 2014-07-15 open Assets:CreditUnion:Saving 2014-07-15 open Assets:FedIncTaxDeposits 2014-07-15 open Assets:Deferred:R-403b 2014-07-15 open Expenses:OASI 2014-07-15 open Expenses:Medicare 2014-07-15 open Expenses:MedicalAid 2014-07-15 open Expenses:SalReduction:HealthInsurance 2014-07-15 open Income:Gross:Emp1 2014-07-15 open Income:EmplContrib:Emp1:Retirement 2014-01-01 open Assets:FSA ; This way of setting up an FSA looks pretty good. It recognizes the ; rule that the designated amount for the year is immediately available ; (in the Asset account), and that we are obliged to make contributions ; to fund it over the course of the year (the Liability account). 2014-01-01 open Liabilities:FSA 2014-01-01 ! "Set up FSA for 2014" Assets:FSA 2000 USD Liabilities:FSA -2000 USD 2014-07-15 ! "Emp1 Paystub" Income:Gross:Emp1 -6000 USD Assets:Bank:Checking 3000 USD Assets:CreditUnion:Saving 1000 USD Assets:FedIncTaxDeposits 750 USD Expenses:OASI 375 USD Expenses:Medicare 100 USD Expenses:MedicalAid 10 USD Assets:Deferred:R-403b 600 USD Liabilities:FSA 75 USD Expenses:SalReduction:HealthInsurance 90 USD Income:EmplContrib:Emp1:Retirement -600 USD Assets:Deferred:R-403b 2014-01-01 open Expenses:Medical 2014-07-20 ! "Direct expense from FSA" Expenses:Medical 25 USD Assets:FSA 2014-07-20 ! "Medical expense from checking" Expenses:Medical 25 USD Assets:Bank:Checking 2014-07-20 ! "Medical expense reimbursed from FSA" Assets:Bank:Checking 25 USD Assets:FSA ``` -------------------------------- ### Run All Unit Tests with Bazel Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Execute all unit tests defined in the Beancount project using Bazel. Bazel's detailed dependency tracking ensures only touched targets are re-tested, optimizing iterative development. ```bash bazel test //... ``` -------------------------------- ### Clear Asset and Liability Accounts in Beancount Source: https://beancount.github.io/docs/index.html/sharing_expenses_with_beancount This Beancount example demonstrates the process of clearing final balances of asset and liability accounts at the end of a trip. It involves transferring remaining funds to participants' income accounts, ensuring all trip balances are zeroed out and cash put forward is accounted for, followed by balance assertions to confirm zero balances. ```Beancount 2015-03-06 * "Final transfer to clear internal balances to external ones" Assets:Cash:Pesos -65 MXN Income:Martin:Cash:Foreign 60 MXN Income:Caroline:Cash 5 MXN Assets:Cash:Martin -330 USD Income:Martin:Cash 330 USD Assets:Cash:Caroline -140 USD Income:Caroline:Cash 140 USD 2015-03-07 balance Assets:Cash:Pesos 0 MXN 2015-03-07 balance Assets:Cash:Pesos 0 USD 2015-03-07 balance Assets:Cash:Martin 0 USD 2015-03-07 balance Assets:Cash:Caroline 0 USD ``` -------------------------------- ### Install Beancount in Editable Mode Source: https://beancount.github.io/docs/index.html/installing_beancount_v3 Installs Beancount in editable mode, allowing developers to modify the source code directly without reinstallation. The --no-build-isolation flag is not required on Windows. ```python (venv) C:\_code\t\beancount> py -m pip install --editable . ``` -------------------------------- ### Format Account Balances as a Hierarchical Tree Source: https://beancount.github.io/docs/index.html/tutorial_example Demonstrates how to use the `treeify` tool to render a hierarchical list of accounts from a `bean-report` output into a more readable tree structure. This tool is versatile and can be configured for various data patterns. ```Shell bean-report example.beancount balances | treeify ``` -------------------------------- ### Generate Restricted and Cost-Based Balances Reports Source: https://beancount.github.io/docs/index.html/tutorial_example Learn how to generate a detailed balances report, restricting the output to specific accounts of interest. Additionally, see how to render the cost basis for investment subaccounts using the `--cost` option. ```Shell bean-report example.beancount balances -e ETrade ``` ```Shell bean-report example.beancount balances -e ETrade --cost ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.