### Docker Compose Setup for Lazy Beancount Source: https://github.com/evernight/lazy-beancount/blob/main/README.md This section details how to set up and run Lazy Beancount using Docker Compose. It requires Docker to be installed and involves cloning the repository, navigating to the example data directory, and running the docker compose up command. This pulls the latest package from Docker Hub and starts the service, accessible at http://localhost:8777. ```bash git clone https://github.com/Evernight/lazy-beancount cd lazy-beancount/example_data env UID=$(id -u) GID=$(id -g) docker compose up ``` -------------------------------- ### Local Development Setup with Conda for Lazy Beancount Source: https://github.com/evernight/lazy-beancount/blob/main/README.md This section guides users through setting up a local development environment for Lazy Beancount using Conda. It covers cloning the repository, installing Miniconda, creating and activating a Conda environment, installing required Python packages via pip, and finally running the Fava web interface for exploring the ledger data. ```bash git clone https://github.com/Evernight/lazy-beancount cd lazy-beancount brew install miniconda conda create -n lazy-beancount-env python=3.12.11 conda activate lazy-beancount-env pip3 install -r requirements.txt fava main.bean ``` -------------------------------- ### Run Beancount Import with Web Interface Source: https://context7.com/evernight/lazy-beancount/llms.txt This command starts the beancount-importers web interface, allowing users to configure and run imports. It requires the journal file and the importers configuration file to be specified. Ensure `beancount-importers` is installed. ```bash # Start beancount-import web interface python3 -m beancount_importers.beancount_import_run \ --address 0.0.0.0 \ --journal_file main.bean \ --importers_config_file importers_config.yml ``` -------------------------------- ### Run Lazy Beancount with Docker Compose Source: https://context7.com/evernight/lazy-beancount/llms.txt This command clones the Lazy Beancount repository, navigates to the example data directory, and starts the services using Docker Compose. It requires the user's UID and GID for proper permissions. Services become available at specified localhost ports. ```bash git clone https://github.com/Evernight/lazy-beancount cd lazy-beancount/example_data env UID=$(id -u) GID=$(id -g) docker compose up # Services will be available at: # - Main UI: http://localhost:8777/ # - Fava: http://localhost:5003/ # - Import interface: http://localhost:8101/ ``` -------------------------------- ### Run Lazy Beancount with Docker CLI Source: https://context7.com/evernight/lazy-beancount/llms.txt This section provides instructions for running Lazy Beancount using the Docker CLI. It includes pulling the latest image and running the container with either example data or custom data, as well as support for Podman. ```bash docker pull vandereer/lazy-beancount:latest # Run with example data ./lazy_beancount.sh example_data # Run with your own data ./lazy_beancount.sh data # Run with Podman instead of Docker ./lazy_beancount.sh data podman ``` -------------------------------- ### Launch Streamlit Frontend and Configure Environment Source: https://context7.com/evernight/lazy-beancount/llms.txt This Python script sets up environment variables for the Lazy Beancount services and launches the Streamlit frontend. The frontend provides multiple pages for Fava, Totals, Import, Prices, Logs, and Configuration. ```python import streamlit as st import os # Environment variables for service configuration os.environ["LAZY_BEANCOUNT_HOST"] = "localhost" os.environ["LAZY_BEANCOUNT_PORT"] = "8777" os.environ["FAVA_PORT"] = "5003" os.environ["BEANCOUNT_IMPORT_PORT"] = "8101" # Run: streamlit run frontend.py # Provides 6 pages: # - Fava: Embedded Fava interface # - Totals: Balance entry UI with date selector # - Import: File upload interface for bank statements # - Prices: Commodity price fetching via bean-price # - Logs: System logs viewer # - Config: YAML configuration editor ``` -------------------------------- ### Launch All Daemons in Bash Source: https://context7.com/evernight/lazy-beancount/llms.txt This bash script initiates multiple services: Fava, beancount-import, and Streamlit. It directs all logs to 'lazy-beancount.log' and provides URLs for accessing each service. ```bash # Start Fava, beancount-import, and Streamlit bash run_daemons.sh # Services start on: # - Fava: http://localhost:5003 # - Beancount Import: http://localhost:8101 # - Streamlit: http://localhost:8777 # All logs are written to lazy-beancount.log tail -f lazy-beancount.log ``` -------------------------------- ### Build Lazy Beancount Docker Image Source: https://context7.com/evernight/lazy-beancount/llms.txt Instructions for building the Lazy Beancount Docker image locally. It involves cloning the repository and using the `docker build` command. An additional command is provided for building multi-platform images. ```bash git clone https://github.com/Evernight/lazy-beancount cd lazy-beancount docker build . -t vandereer/lazy-beancount:latest # Build multi-platform image make docker-build ``` -------------------------------- ### Generate Beancount Accounts via Command Line Source: https://context7.com/evernight/lazy-beancount/llms.txt This command demonstrates how to use the `gen_accounts.py` script from the command line to generate Beancount account opening directives. It requires specifying the configuration file containing the account structure. ```bash # Generate account opening directives python gen_accounts.py --config_file accounts_config.yml accounts ``` -------------------------------- ### Docker Image Pull and Build for Lazy Beancount Source: https://github.com/evernight/lazy-beancount/blob/main/README.md Instructions for obtaining the Lazy Beancount Docker image, either by pulling the latest version from Docker Hub or by building it from source. The build process involves cloning the repository and running the docker build command. The document also shows how to execute the Lazy Beancount script within the container for managing data. ```bash docker pull vandereer/lazy-beancount:latest git clone https://github.com/Evernight/lazy-beancount cd lazy-beancount docker build . -t vandereer/lazy-beancount:latest ./lazy_beancount.sh example_data ./lazy_beancount.sh data ``` -------------------------------- ### Generate Account Entries with gen_accounts.py Source: https://context7.com/evernight/lazy-beancount/llms.txt Use the gen_accounts.py script to generate initial or updated balance entries. It requires a configuration file and optionally accepts a specific date for updates. Ensure the configuration file is correctly specified. ```bash python gen_accounts.py --config_file accounts_config.yml totals_init python gen_accounts.py --config_file accounts_config.yml totals_update 2024-01-15 ``` -------------------------------- ### Generate Beancount Account Definitions from YAML Source: https://context7.com/evernight/lazy-beancount/llms.txt Python code to parse account configurations from a YAML file or a string and generate Beancount account opening directives. It uses the `gen_accounts` module and requires `datetime` for date handling. The output includes `open`, `Equity:OpeningBalances`, and `Income:Unattributed` directives. ```python import gen_accounts from datetime import datetime # Parse configuration from YAML file config = gen_accounts.parse_config("accounts_config.yml") # Returns: ParsedConfig(account_configs=list, opening_balances_date=datetime, default_booking_method=str) # Parse from string yaml_config = """ opening_balances_date: "2023-12-01" default_booking_method: FIFO cash: - MyBank: - Checking: currencies: [USD, EUR] - Savings: - GBP opaque_funds_valuation: - Broker401k: - Total: currencies: [USD] booking_method: FIFO investments: - MyBroker: - AAPL: booking_method: LIFO - MSFT liabilities: - CreditCard: - Main: currencies: [USD] """ parsed = gen_accounts.parse_config_from_string(yaml_config) # Generate Beancount account opening directives account_directives = gen_accounts.gen_accounts(parsed) print(account_directives) # Output: # ; account MyBank:Checking (cash) # 1970-01-01 open Assets:MyBank:Checking "FIFO" # 1970-01-01 open Equity:OpeningBalances:MyBank:Checking # 1970-01-01 open Income:Unattributed:MyBank:Checking # ... ``` -------------------------------- ### Fetch Prices via Bean-Price Tool Source: https://context7.com/evernight/lazy-beancount/llms.txt The `bean-price` command-line tool fetches commodity prices from various sources. Use the `-i` flag for interactive mode or to specify a date. The output format shows the date, price directive, currency, and value. ```bash # Fetch prices for specific date bean-price main.bean -i --date=2024-01-15 # Fetch prices with interactive mode bean-price main.bean -i -c # Output format: # 2024-01-15 price EUR 1.08950000 USD # 2024-01-15 price BTC 42500.00000000 USD ``` -------------------------------- ### Configure Bank Statement Importers (YAML) Source: https://context7.com/evernight/lazy-beancount/llms.txt This YAML configuration file defines various bank statement importers. Each entry specifies the importer type, the target Beancount account, the currency, and any specific parameters required for that importer. Ensure the file path is correct when running the import process. ```yaml # importers_config.yml importers: monzo_checking: importer: monzo account: Assets:Monzo:Cash currency: GBP params: ignore_bank_categories: True revolut_eur: importer: revolut account: Assets:Revolut:Cash currency: EUR wise_usd: importer: wise account: Assets:Wise:Cash currency: USD ibkr_brokerage: importer: ibkr account: Assets:IB:Cash currency: USD params: cash_account: "Assets:IB:Cash" assets_account: "Assets:IB:{symbol}" div_account: "Income:IB:{symbol}:Div" interest_account: "Income:IB:Interest" wht_account: "Expenses:IB:WithholdingTax" fees_account: "Expenses:IB:Commissions" pnl_account: "Income:IB:PnL" binance_crypto: importer: binance account: Assets:Binance currency: USD params: spot_wallet_account: "Assets:Crypto:Binance:Cash" fees_account: "Expenses:Fees:Crypto:Binance" p2p_account: "Assets:Crypto:Binance:P2P" savings_account: "Assets:Crypto:Binance:Savings" income_interest_account: "Income:Crypto:Binance:Interest" income_referal_account: "Income:Crypto:Binance:Referal" income_distributions_account: "Income:Crypto:Binance:Distribution" ``` -------------------------------- ### Load and Display Totals with Streamlit Source: https://context7.com/evernight/lazy-beancount/llms.txt This Python script loads and parses financial totals from a generated `.gen.bean` file. It extracts balance and valuation directives and prepares the data for display in a Streamlit data editor. Ensure the `gen_accounts` module and the specified filename exist. ```python import streamlit as st import gen_accounts import os import re from datetime import datetime # Parse configuration config = gen_accounts.parse_config("accounts_config.yml") # Read existing totals file filename = "totals/update-2024-01-15.gen.bean" values = {} if os.path.exists(filename): with open(filename, "r") as f: for line in f: # Parse balance directives balance_match = re.search( r".+\s+balance\s+\w+\:([\w\:]+)\s+([-\d\.]+)\s+(\w+).*", line ) if balance_match: account = balance_match.group(1) amount = float(balance_match.group(2)) currency = balance_match.group(3) values[(account, currency)] = amount # Parse valuation directives valuation_match = re.search( r".+\s+\"valuation\"\s+\w+\:([\w\:]+)\s+([-\d\.]+)\s+(\w+).*", line ) if valuation_match: account = valuation_match.group(1) amount = float(valuation_match.group(2)) currency = valuation_match.group(3) values[(account, currency)] = amount # Create data editor for balance entry rows = [] for cfg in config.account_configs: if cfg.type in ["cash", "opaque_funds", "opaque_funds_valuation", "liabilities"]: for currency in cfg.currencies: rows.append({ "name": cfg.name, "currency": currency, "value": values.get((cfg.name, currency), None) }) # Display in Streamlit (requires running in Streamlit context) # edited_rows = st.data_editor(rows, use_container_width=True) ``` -------------------------------- ### Generate Beancount Balance Update Entries Source: https://context7.com/evernight/lazy-beancount/llms.txt Python code to generate Beancount balance update entries from account configurations and provided values. It can generate initial balance entries (using `Equity:OpeningBalances`) or regular updates (using `Income`/`Expenses` for padding). It also supports commenting out specific accounts. ```python from datetime import datetime, timedelta config = gen_accounts.parse_config("accounts_config.yml") # Account balances as of specific date date = datetime(2024, 1, 15) values = { ("MyBank:Checking", "USD"): 5000.00, ("MyBank:Checking", "EUR"): 2500.50, ("MyBank:Savings", "GBP"): 10000.00, ("Broker401k:Total", "USD"): 150000.00, } # Generate initial balances (uses Equity:OpeningBalances) initial_entries = gen_accounts.gen_update_totals( config, date, values, is_initial_check=True ) # Generate regular balance updates (uses Income/Expenses accounts for pad) update_entries = gen_accounts.gen_update_totals( config, date, values, is_initial_check=False ) print(update_entries) # Output: # 2024-01-14 pad Assets:MyBank:Checking Expenses:Unattributed:MyBank:Checking # 2024-01-14 pad Assets:MyBank:Savings Expenses:Unattributed:MyBank:Savings # 2024-01-14 pad Assets:Broker401k:Total Expenses:Unattributed:Broker401k:Total # # 2024-01-15 balance Assets:MyBank:Checking 5000.00 USD # 2024-01-15 balance Assets:MyBank:Checking 2500.50 EUR # 2024-01-15 balance Assets:MyBank:Savings 10000.00 GBP # 2024-01-15 custom "valuation" Assets:Broker401k:Total 150000.00 USD # Comment out specific accounts (useful for unused pad operations) commented = gen_accounts.gen_update_totals( config, date, values, is_initial_check=False, comment_accounts={"Assets:MyBank:Checking"} ) ``` -------------------------------- ### Executing Commands within Lazy Beancount Docker Container Source: https://github.com/evernight/lazy-beancount/blob/main/README.md This snippet demonstrates how to execute specific commands within a running Lazy Beancount Docker container. The `docker exec` command allows for interactive execution of tools like `bean-price` to process ledger files and retrieve price data, specifying dates for the operation. ```bash docker exec -it lazybean bean-price example_data/main.bean -i --date=2024-01-05 ``` -------------------------------- ### Execute Beancount Commands in Docker Container Source: https://context7.com/evernight/lazy-beancount/llms.txt A collection of bash commands to execute various Beancount operations within a Docker container named 'lazybean'. These include checking file integrity, querying account balances, generating reports, fetching prices, and running the Fava web interface. ```bash # Check file for errors docker exec -it lazybean bean-check main.bean # Query accounts docker exec -it lazybean bean-query main.bean "SELECT account, sum(position) WHERE account ~ 'Assets'" # Generate reports docker exec -it lazybean bean-report main.bean holdings # Fetch prices for specific date docker exec -it lazybean bean-price main.bean -i --date=2024-01-15 # Run Fava directly docker exec -it lazybean fava main.bean ``` -------------------------------- ### Configure Commodity Prices (YAML) Source: https://context7.com/evernight/lazy-beancount/llms.txt This YAML configuration file defines commodities and their pricing multipliers. It's used to standardize or adjust commodity values for Beancount. The `multiplier` field can be used for unit conversions or to set a base value. ```yaml # prices_config.yml commodities: - EUR: multiplier: 1.0 - BTC: multiplier: 0.001 # Adjust for unit conversion if needed ``` -------------------------------- ### Process Commodity Prices with Multipliers in Python Source: https://context7.com/evernight/lazy-beancount/llms.txt This script processes commodity prices fetched from beancount, applies custom multipliers defined in a YAML configuration, and saves the updated prices to a file. It requires the 'subprocess', 're', 'decimal', and 'yaml' Python libraries. ```python import subprocess import re from decimal import Decimal import yaml # Load commodities configuration with open("prices_config.yml", "r") as f: prices_config = yaml.safe_load(f) commodities_map = {} for commodity in prices_config.get("commodities", []): for symbol, config in commodity.items(): commodities_map[symbol] = config # Fetch prices date = "2024-01-15" command = ["bean-price", "main.bean", "-i", "-c", f"--date={date}"] output = subprocess.check_output(command) # Process and apply multipliers processed_prices = [] for line in output.decode("utf-8").split("\n"): match = re.search(r"^([\d-]+)\s+price\s+([\w-]+)\s+([\d\\.]+)\s+([\w-]+)", line) if match: price_date = match.group(1) commodity = match.group(2) value = match.group(3) currency = match.group(4) updated_value = Decimal(value) if commodity in commodities_map and "multiplier" in commodities_map[commodity]: updated_value *= Decimal(commodities_map[commodity]["multiplier"]) if updated_value > 0: processed_prices.append( f"{price_date} price {commodity:20} {updated_value:.8f} {currency}" ) # Save to file with open(f"prices/prices-{date}.gen.bean", "w") as f: f.write("\n".join(processed_prices)) ``` -------------------------------- ### Trigger Fava Reload Programmatically Source: https://context7.com/evernight/lazy-beancount/llms.txt This Python function uses the subprocess module to touch the main ledger file (`main.bean`), which triggers a reload in Fava. This is useful for ensuring Fava reflects recent changes without manual intervention. ```python import subprocess def trigger_fava_reload(): """Touch main ledger file to trigger Fava reload""" subprocess.check_output(["touch", "main.bean"]) print("Fava reloaded") trigger_fava_reload() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.