Metadata-Version: 2.3
Name: bean-inquiry
Version: 0.2.0
Summary: 
Author: aleyoscar
Author-email: mail@aleyoscar.com
Requires-Python: >=3.11
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: beanquery (>=0.2.0,<0.3.0)
Requires-Dist: typer (>=0.17.4,<0.18.0)
Description-Content-Type: text/markdown

# Beancount INquiry

A CLI tool to INject parameters into Beancount queries specified in your ledger

## Usage

Beancount INquiry will inject parameters into query directives specified in your ledger file using pythons `.format` function, and so uses the same syntax. Here is an example query directive with two parameters:

```
2025-01-01 query "balance" "SELECT date, account, sum(number) as total WHERE account ~ '{}' AND date >= {} ORDER BY account"
```

And then pass in the ledger, the name of the query, and the list of parameters

```
bean-inquiry ledger.beancount balance Assets 2014-05-01
```

You can also use indexed placeholders:

```
2025-01-01 query "balance" "SELECT date, {0}, sum(number) as total WHERE {0} ~ '{1}' AND date >= {2} ORDER BY {0}"
...
bean-inquiry ledger.beancount balance account Assets:Bank 2025-05-01
```

And named placeholders, with parameter keys separated with a colon:

```
2025-01-01 query "balance" "SELECT date, {select}, sum(number) as total WHERE {select} ~ '{account}' AND date >= {date} ORDER BY {select}"
...
bean-inquiry ledger.beancount balance select:account account:Assets:Bank date:2025-05-01
```

See the `--help` for more options

```
bean-inquiry --help
```

## Options

Usage: bean-inquiry [OPTIONS] LEDGER [NAME] [PARAMS]...

Beancount INquiry - A CLI tool to inject parameters INto Beancount queries
located in your ledger.

╭─ Arguments ─────────────────────────────────────────────────────────────────╮
│ *    ledger      FILE         The Beancount ledger file to parse [required] │
│      name        [NAME]       The name of the query to parse                │
│      params      [PARAMS]...  List of parameters to parse                   │
╰─────────────────────────────────────────────────────────────────────────────╯
╭─ Options ───────────────────────────────────────────────────────────────────╮
│ --format              -f      [text|csv]  Output format: 'text' or 'csv'    │
│                                           [default: text]                   │
│ --check               -c                  Check a query for what parameters │
│                                           are needed                        │
│ --list                -l                  List all queries available in     │
│                                           ledger                            │
│ --install-completion                      Install completion for the        │
│                                           current shell.                    │
│ --show-completion                         Show completion for the current   │
│                                           shell, to copy it or customize    │
│                                           the installation.                 │
│ --help                                    Show this message and exit.       │
╰─────────────────────────────────────────────────────────────────────────────╯

## Installation

### Pipx (recommended)

Install using pipx from [PyPi](https://pypi.org)

```
pipx install beancount-inquiry
bean-inquiry --help
```

### Build from source using pipx

Clone this repository and install systemwide using pipx:

```
git clone https://github.com/aleyoscar/beancount-inquiry.git
cd beancount-inquiry
pipx install .
bean-inquiry --help
```

### Run using poetry

Clone this repository and run using [poetry](https://python-poetry.org/)

```
git clone https://github.com/aleyoscar/beancount-inquiry.git
cd beancount-inquiry
poetry install
poetry run bean-inquiry
```

## Dependencies

This project uses [typer](https://typer.tiangolo.com/) for the CLI and [beanquery](https://github.com/beancount/beanquery) for running the queries

