Skip to content

Beancount v3 Specification - Introduction ​

Overview ​

Beancount is a double-entry bookkeeping language for plain text accounting. It provides a simple, human-readable format for recording financial transactions and a set of tools for processing, validating, and querying the data.

Purpose ​

This specification defines:

  1. Syntax - The grammar of Beancount files
  2. Semantics - The meaning of directives and their behavior
  3. Validation - Rules for detecting errors
  4. Processing - How files are loaded and transformed

Design Principles ​

Plain Text ​

All data is stored in human-readable text files:

  • Version controllable (git, mercurial)
  • Grep-able and scriptable
  • No proprietary formats
  • Long-term archival friendly

Double-Entry Accounting ​

Every transaction must balance:

  • Sum of debits equals sum of credits
  • Enforced by the parser/validator
  • Prevents common bookkeeping errors

Declarative ​

Files declare facts, not procedures:

  • No imperative control flow
  • Order within files doesn't matter (directives are sorted by date)
  • Idempotent processing

Extensible ​

Support for custom data and transformations:

  • Metadata on any directive
  • Custom directives for arbitrary data
  • Plugin system for transformations

Document Structure ​

Core Specification ​

DocumentDescription
lexical.mdTokens, whitespace, comments, encoding
syntax.mdGrammar overview, file structure
posting.mdPosting structure within transactions
amounts.mdNumber and amount formats
costs.mdCost basis specification
prices.mdPrice annotations
metadata.mdKey-value metadata
tags-links.mdTags and links

Directives ​

DirectiveDescription
transaction.mdFinancial exchanges
open.mdAccount declarations
close.mdAccount closures
balance.mdBalance assertions
pad.mdAutomatic balancing
commodity.mdCurrency declarations
price.mdMarket prices
event.mdVariable tracking
note.mdAccount notes
document.mdFile attachments
query.mdEmbedded queries
custom.mdUser-defined directives
option.mdConfiguration
plugin.mdTransformations
include.mdFile inclusion

Validation ​

DocumentDescription
validation/accounts.mdAccount lifecycle
validation/balance.mdBalance checking
validation/commodities.mdCurrency rules
validation/duplicates.mdDuplicate detection
errors.mdError codes catalog

Semantics ​

DocumentDescription
booking.mdLot matching methods
tolerances.mdBalance tolerances
includes.mdInclude semantics

Terminology ​

RFC 2119 Keywords ​

This specification uses RFC 2119 keywords:

KeywordMeaning
MUSTAbsolute requirement
MUST NOTAbsolute prohibition
SHOULDRecommended but not required
SHOULD NOTNot recommended but not prohibited
MAYOptional

Definitions ​

TermDefinition
DirectiveA dated entry in the ledger
TransactionA directive recording a financial exchange
PostingA single line within a transaction
AccountA named container for tracking value
CommodityA unit of measurement (currency, stock, etc.)
AmountA number paired with a commodity
CostThe acquisition price of a commodity
PriceThe market exchange rate
LotA specific acquisition of a commodity
InventoryThe collection of lots in an account

Version History ​

VersionDateChanges
v3.02024Current specification
v2.02016Python 3, Unicode support
v1.02012Initial release

Conformance ​

Implementations claiming Beancount compatibility MUST:

  1. Parse all valid Beancount syntax
  2. Reject all invalid syntax with appropriate errors
  3. Implement all required validation rules
  4. Support the standard booking methods

See conformance/ for the conformance testing program.

Example ​

A minimal Beancount file:

beancount
; Personal Finance Ledger
option "title" "My Finances"
option "operating_currency" "USD"

; Account definitions
2024-01-01 open Assets:Checking USD
2024-01-01 open Expenses:Food
2024-01-01 open Income:Salary

; Transactions
2024-01-15 * "Employer" "Monthly salary"
  Assets:Checking    3000.00 USD
  Income:Salary

2024-01-16 * "Grocery Store" "Weekly groceries"
  Expenses:Food       85.50 USD
  Assets:Checking

; Balance assertion
2024-01-17 balance Assets:Checking  2914.50 USD

References ​