Skip to main content

A CLI tool to manage Beancount ledgers

Project description

beancount-cli

A robust command-line interface and Python library for programmatically managing Beancount ledgers. Designed for AI agents and automation workflows.

Features

  • Validation: Wrap bean-check to validate ledgers programmatically.
  • Visualization: View the file inclusion tree (tree command).
  • Transactions:
    • List transactions with regex filtering (account, payee, tags).
    • Add transactions via CLI arguments or JSON (stdin supported).
    • Draft mode support (flag !).
  • Entities:
    • Manage Accounts (list, create).
    • Manage Commodities (create).
    • Manage Prices (fetch, update).
  • Formatting:
    • Auto-format ledgers (bean-format wrapper).
    • Global output formatting: --format support (table, json, csv) for all data commands.
  • Reporting: Generate balance, holding, and audit reports with multi-currency conversion.
  • Composability: Built for Unix piping (json | csv) and batch processing via STDIN.
  • Configuration: Custom Beancount directives for routing new entries to specific files.

Installation

Install using uv or pip:

uv pip install beancount-cli
# or
pip install beancount-cli

For development:

uv sync

Usage

Global Formatting Flag

All data-retrieval and reporting commands support the --format flag.

# Default human-readable table
bean report bs

# Machine-readable CSV (highly token-efficient for AI agents)
bean --format csv transaction list

# Structural JSON (perfect for piping into jq or other scripts)
bean --format json account list

Check Ledger

Validate your ledger file:

bean check main.beancount

Format Ledger

Format your ledger file in-place (uses bean-format):

bean format main.beancount

View Inclusion Tree

Visualize the tree of included files:

bean tree main.beancount

Reports

Generate specialized accounting reports with multi-currency support:

# Balance Sheet (Assets, Liabilities, Equity)
bean report balance-sheet main.beancount

# Trial Balance (All accounts including Income/Expenses)
bean report trial-balance main.beancount

# Holdings (Net worth per Asset account)
bean report holdings main.beancount

# Audit a specific currency (Source of Exposure)
bean report audit USD main.beancount

[!TIP] Convenience aliases are supported: bs (balance-sheet) and trial (trial-balance).

Unified Currency Reporting

Use the --convert and --valuation flags for a consolidated view:

# View Trial Balance in USD using historical cost
bean report trial main.beancount --convert USD --valuation cost

# View Balance Sheet in EUR using current market prices
bean report bs main.beancount --convert EUR --valuation market
Valuation Description Use Case
market (default) Uses latest prices from the ledger. Current Net Worth tracking.
cost Uses historical price basis ({}). Accounting Verification (proving balance).

List Transactions:

bean transaction list main.beancount --account "Assets:US:.*" --payee "Amazon"

Add Transaction:

# JSON via argument
bean transaction add main.beancount --json '{"date": "2023-10-27", ...}'

# JSON via stdin (Recommended for complex data)
cat tx.json | bean transaction add main.beancount --json -

# Create as Draft (!)
bean transaction add main.beancount --json ... --draft

Manage Accounts & Commodities

All creation commands (transaction add, account create, commodity create) support batch processing via JSON arrays on STDIN.

# Batch add transactions from a file
cat txs.json | bean transaction add --json -

# Pipe accounts from one ledger to another
bean --format json account list --file old.beancount | bean account create --json -

Standard CLI usage:

# List Accounts
bean account list

# Create Account
bean account create --name "Assets:NewBank" --currency "USD"

# Create Commodity
bean commodity create "BTC" --name "Bitcoin"

# Fetch and Update Prices
bean price --update

beancount-cli is specifically optimized for AI agents, providing both operational guidance and machine-readable interfaces.

Agent Documentation

We provide specialized documentation for different types of AI interactions:

  • AGENTS.md: Guide for AI End Agents operating the CLI (prompting strategies, token optimization, batch workflows).
  • CODING_AGENTS.md: Mandatory rules for AI Coding Agents modifying the source code (Value Objects, Fail-Fast rules, type safety).

Transaction Schema

Agents can dynamically retrieve the JSON schema for transactions to ensure valid data generation:

bean transaction schema

Complex Transaction Example

Agents should aim to generate JSON in this format for a standard purchase with multiple postings:

{
  "date": "2023-10-27",
  "payee": "Amazon",
  "narration": "Office supplies",
  "postings": [
    {
      "account": "Expenses:Office:Supplies",
      "units": { "number": 45.99, "currency": "USD" }
    },
    {
      "account": "Liabilities:US:Chase:Slate",
      "units": { "number": -45.99, "currency": "USD" }
    }
  ]
}

Scripting with uv run

For reliable cross-platform execution in agent workflows:

uv run bean transaction add --json - < tx.json

Configuration

Ledger Discovery

bean uses a 4-tier discovery logic to find your ledger file automatically:

  1. Explicit Argument: Passing the filename directly (e.g. bean check my.beancount).
  2. BEANCOUNT_FILE: Direct path to a ledger file.
  3. BEANCOUNT_PATH: Looks for main.beancount inside this directory.
  4. Local Directory: Fallback to ./main.beancount.

Custom Directives

You can configure where new entries are written using custom directives in your Beancount file.

Note: custom directives require a date (e.g. 2023-01-01).

2023-01-01 custom "cli-config" "new_transaction_file" "inbox.beancount"
2023-01-01 custom "cli-config" "new_account_file" "accounts.beancount"
2023-01-01 custom "cli-config" "new_commodity_file" "commodities.beancount"

Context-Aware Insertion: You can use placeholders to route transactions to dynamic paths:

2023-01-01 custom "cli-config" "new_transaction_file" "{year}/{month}/txs.beancount"

Supported placeholders: {year}, {month}, {day}, {payee}, {slug}.

Directory Mode (One file per transaction): If new_transaction_file points to a directory, bean will create a new file for each transaction inside that directory, named with an ISO timestamp.

2023-01-01 custom "cli-config" "new_transaction_file" "inbox/"

Development

Run tests:

uv run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

beancount_cli-0.2.3.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

beancount_cli-0.2.3-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file beancount_cli-0.2.3.tar.gz.

File metadata

  • Download URL: beancount_cli-0.2.3.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for beancount_cli-0.2.3.tar.gz
Algorithm Hash digest
SHA256 94d3b97a7fc542612dc4bddef52dbda16e4bd6c18d253b2d9c9214e941f59239
MD5 f7364912cff2fd3c638aed54a9f0e635
BLAKE2b-256 94e08efa7ff4c6ef6b8693344fc8cd988f1b9cc69ce6e67a6312d945d8e1629c

See more details on using hashes here.

File details

Details for the file beancount_cli-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: beancount_cli-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for beancount_cli-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e9c9fcc4e5838e6fa0c47cfb87c4f281588a3b0771a463a0a33e48aa0dd6327f
MD5 4b20d5c03328a83e5800eac737076ae4
BLAKE2b-256 7b3897275c482ed1553d341d8b9131e0dbd5d83a3737dbb0d21554cb93834d01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page