Beancount Language Syntax
This provides a concise yet comprehensive reference for the Beancount language syntax, blending practical structure, rules, and examples. For more details, see the Cheat Sheet.
Overview
Beancount is a plain-text double-entry accounting system. Its language is structured around three main building blocks:
- Commodities (currencies, stocks, points, etc.)
- Accounts (hierarchical, categorized ledgers)
- Directives (dated entries recording events or configuration)
Commodities
Commodities are always written in uppercase, e.g., USD
, EUR
, AAPL
, BTC
, MILES
, HOURS
.
Accounts
Accounts are colon-separated, capitalized hierarchical names. They must begin with one of the five root account types:
Name | Type | Typical Contents | Example |
---|---|---|---|
Assets | + | Cash, Bank, Investments | Assets:Checking |
Liabilities | - | Credit Cards, Loans | Liabilities:CreditCard |
Income | - | Salary, Interest | Income:EmployerA |
Expenses | + | Purchases, Bills | Expenses:Food:Dining |
Equity | - | Opening/Closing Balances | Equity:Opening-Balances |
- Components must be capitalized, separated by colons (
:
), with no spaces. - Numbers and dashes are allowed in components.
- The root account names can be customized via options (see below).
Directives
Directives are the core statements in a Beancount file. Most start with a date, followed by a directive type and arguments. They are processed in chronological order (by date), not file order.
General format:
YYYY-MM-DD <directive> <arguments...>
Common Directives & Examples
Opening and Closing Accounts
2023-01-01 open Assets:Checking USD,EUR ; Optionally specify allowed currencies
2023-12-31 close Assets:Checking
Declaring Commodities
2020-07-22 commodity AAPL
name: "Apple Inc."
Price Declarations
2022-04-30 price AAPL 150.00 USD