Skip to main content

Translate Ledger CLI query syntax into BQL

Project description

ledger2bql

Translate Ledger CLI query syntax into BQL

Implemented in Python.

The package is available at https://pypi.org/project/ledger2bql/.

Introduction

BQL is quite a powerful language for slicing and dicing Beancount data. But, when all you need are simple queries, writing every field and filter seems tedios. In comparison, Ledger CLI's syntax is short and efficient. A simple l b bank will list all bank accounts, assuming a well-organized account tree.

The purpose of this project, a simple CLI utility, is to accept a Ledger-like syntax, generate an appropriate BQL statement, and run it for you.

Development

Setup

Clone the repository. Add an .env file, specifying the BEANCOUNT_FILE location.

BEANCOUNT_FILE=tests/sample_ledger.bean
uv sync

Build

uv build

Run

uv run ledger2bql

or run

l ...

Usage

Install the package:

uv pip install ledger2bql
# or
uv tool install ledger2bql

Set the BEANCOUNT_FILE variable to point to your Beancount ledger file. You can create an .env file, to customize different ledgers for different folders.

Run

ledger2bql b card
ledger2bql r card -b 2025-08-01

To get the list of available parameters, simply run

ledger2bql
ledger2bql bal --help
ledger2bql reg --help

Output

Balance

Running

l b

will output

Your BQL query is:

SELECT account, sum(position) GROUP BY account ORDER BY account ASC

+--------------------------+---------------+
| Account                  |       Balance |
|--------------------------+---------------|
| Assets:Bank:Checking     |  1,900.00 EUR |
| Assets:Cash:Pocket-Money |    -20.00 EUR |
| Equity:Opening-Balances  | -1,000.00 EUR |
| Expenses:Food            |    100.00 EUR |
| Expenses:Sweets          |     20.00 EUR |
| Income:Salary            | -1,000.00 EUR |
+--------------------------+---------------+

Register

Command

l r exp

outputs

Your BQL query is:

SELECT date, account, payee, narration, position WHERE account ~ 'exp' ORDER BY date, account

+------------+-----------------+----------------+-------------+------------+
| Date       | Account         | Payee          | Narration   |     Amount |
|------------+-----------------+----------------+-------------+------------|
| 2025-02-01 | Expenses:Sweets | Ice Cream Shop | Ice Cream   |  20.00 EUR |
| 2025-03-01 | Expenses:Food   | Grocery Store  | Groceries   | 100.00 EUR |
+------------+-----------------+----------------+-------------+------------+

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

ledger2bql-0.5.0.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

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

ledger2bql-0.5.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file ledger2bql-0.5.0.tar.gz.

File metadata

  • Download URL: ledger2bql-0.5.0.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for ledger2bql-0.5.0.tar.gz
Algorithm Hash digest
SHA256 f7336db11b8ab5e79154da8d32294d8a5931125c447a37c4ea33e8ffea7d7be0
MD5 f7f2c1231f8ca40b3892c4c30b51f597
BLAKE2b-256 196c737e3b52eeb50586ffa837ddb7ec4aaf5587390eed617806cd977e1f754e

See more details on using hashes here.

File details

Details for the file ledger2bql-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: ledger2bql-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for ledger2bql-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60e6a41f1a8bec76ea3acdf38ef3fedaa9e7a0f1864dc4c13d9a92e9217c7aa2
MD5 87b451f3590ae0b8a29d639781e4fda4
BLAKE2b-256 a4554678c76b45de2606c73075d25f700de7a44fa643518bc7a30c2976cab0dc

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