Skip to content

Beancount v3 Format Specification

Overview

Beancount is a double-entry bookkeeping language designed for plain text accounting. This specification defines version 3 of the Beancount format.

Key Features

  • Plain text - Human-readable, version-controllable files
  • Double-entry - Enforced balance in every transaction
  • Multi-currency - Native support for multiple currencies and commodities
  • Cost tracking - Lot-based inventory with multiple booking methods
  • Extensible - Metadata, plugins, and custom directives

Quick Example

beancount
; Options
option "title" "Personal Finances"
option "operating_currency" "USD"

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

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

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

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

Specification Structure

Core Specification

DocumentDescription
spec/introduction.mdOverview and terminology
spec/lexical.mdTokens, encoding, whitespace
spec/syntax.mdGrammar and file structure

Directives

DirectiveDocument
Transactionspec/directives/transaction.md
Openspec/directives/open.md
Closespec/directives/close.md
Balancespec/directives/balance.md
Padspec/directives/pad.md
Commodityspec/directives/commodity.md
Pricespec/directives/price.md
Eventspec/directives/event.md
Notespec/directives/note.md
Documentspec/directives/document.md
Queryspec/directives/query.md
Customspec/directives/custom.md
Optionspec/directives/option.md
Pluginspec/directives/plugin.md
Includespec/directives/include.md

Data Elements

ElementDocument
Postingsspec/posting.md
Amountsspec/amounts.md
Costsspec/costs.md
Pricesspec/prices.md
Metadataspec/metadata.md
Tags & Linksspec/tags-links.md

Semantics

TopicDocument
Booking Methodsspec/booking.md
Tolerancesspec/tolerances.md
Include Processingspec/includes.md
Error Codesspec/errors.md

Validation

TopicDocument
Account Lifecyclespec/validation/accounts.md
Balance Checkingspec/validation/balance.md
Currency Rulesspec/validation/commodities.md
Duplicate Detectionspec/validation/duplicates.md

Grammar

FormatFileDescription
PEGgrammar/beancount.pegParsing Expression Grammar
EBNFgrammar/beancount.ebnfISO 14977 EBNF
ABNFgrammar/beancount.abnfRFC 5234 ABNF

Schema

FormatFileDescription
JSON Schemaschema/ast.schema.jsonAST validation
Protocol Buffersschema/ast.protoBinary serialization

Editor Support

Tree-sitter

Complete tree-sitter grammar for syntax highlighting and editor integration:

Query Language

Beancount includes BQL (Beancount Query Language) for querying ledger data:

Migration

File Extension

Beancount files use the .beancount extension:

ledger.beancount
accounts.beancount
2024/january.beancount

Some tools also recognize .bean as an alternative.

Implementations

ImplementationLanguageStatus
beancountPythonReference
rustledgerRustCompatible
beancount-parserRustParser only

Resources

License

This specification is licensed under CC-BY-4.0.