beancount-cli 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- beancount_cli-0.2.0/.gitignore +27 -0
- beancount_cli-0.2.0/CHANGELOG.md +22 -0
- beancount_cli-0.2.0/LICENSE +21 -0
- beancount_cli-0.2.0/PKG-INFO +276 -0
- beancount_cli-0.2.0/README.md +246 -0
- beancount_cli-0.2.0/pyproject.toml +84 -0
- beancount_cli-0.2.0/src/beancount_cli/__init__.py +1 -0
- beancount_cli-0.2.0/src/beancount_cli/adapters.py +100 -0
- beancount_cli-0.2.0/src/beancount_cli/cli.py +755 -0
- beancount_cli-0.2.0/src/beancount_cli/config.py +27 -0
- beancount_cli-0.2.0/src/beancount_cli/formatting.py +233 -0
- beancount_cli-0.2.0/src/beancount_cli/models.py +103 -0
- beancount_cli-0.2.0/src/beancount_cli/py.typed +0 -0
- beancount_cli-0.2.0/src/beancount_cli/services.py +674 -0
- beancount_cli-0.2.0/tests/conftest.py +45 -0
- beancount_cli-0.2.0/tests/smoke_test.py +14 -0
- beancount_cli-0.2.0/tests/test_advanced.py +105 -0
- beancount_cli-0.2.0/tests/test_bql.py +46 -0
- beancount_cli-0.2.0/tests/test_cli.py +163 -0
- beancount_cli-0.2.0/tests/test_coverage_gap.py +253 -0
- beancount_cli-0.2.0/tests/test_models.py +67 -0
- beancount_cli-0.2.0/tests/test_services.py +137 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Environments
|
|
2
|
+
.venv/
|
|
3
|
+
.env
|
|
4
|
+
|
|
5
|
+
# Cache and temporary files
|
|
6
|
+
__pycache__/
|
|
7
|
+
*.pyc
|
|
8
|
+
*.pyo
|
|
9
|
+
*.pyd
|
|
10
|
+
.Python
|
|
11
|
+
env/
|
|
12
|
+
venv/
|
|
13
|
+
.pytest_cache/
|
|
14
|
+
.ruff_cache/
|
|
15
|
+
.coverage
|
|
16
|
+
tmp/
|
|
17
|
+
*_out*.txt
|
|
18
|
+
analyze_output.json
|
|
19
|
+
dist/
|
|
20
|
+
build/
|
|
21
|
+
*.egg-info/
|
|
22
|
+
|
|
23
|
+
# IDEs
|
|
24
|
+
.idea/
|
|
25
|
+
.vscode/
|
|
26
|
+
*.swp
|
|
27
|
+
.DS_Store
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.2.0] - 2026-02-27
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Renamed the CLI entry point from `beancount-cli` to `bean` for better ergonomics and branding.
|
|
12
|
+
- Enhanced CLI help descriptions and examples for better AI agent discoverability.
|
|
13
|
+
- Separated documentation for user-facing agents (`AGENTS.md`) and coding/development agents (`CODING_AGENTS.md`).
|
|
14
|
+
- Added strict type validation and Pydantic schema discovery.
|
|
15
|
+
|
|
16
|
+
## [0.1.0] - Initial Release
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
- Core Beancount CLI functionality.
|
|
21
|
+
- Commands for adding transactions, checking balances, and more.
|
|
22
|
+
- Built-in type hints and validation using Pydantic V2.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Roman Medvedev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: beancount-cli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A CLI tool to manage Beancount ledgers
|
|
5
|
+
Project-URL: Homepage, https://github.com/romamo/beancount-cli
|
|
6
|
+
Project-URL: Repository, https://github.com/romamo/beancount-cli
|
|
7
|
+
Project-URL: Issues, https://github.com/romamo/beancount-cli/issues
|
|
8
|
+
Author-email: Roman Medvedev <pypi@romavm.dev>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: accounting,agent,automation,beancount,cli
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Office/Business :: Financial :: Accounting
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Requires-Dist: beancount>=3.0.0
|
|
24
|
+
Requires-Dist: beanprice>=2.1.0
|
|
25
|
+
Requires-Dist: beanquery>=0.1.0
|
|
26
|
+
Requires-Dist: pydantic-settings>=2.0.0
|
|
27
|
+
Requires-Dist: pydantic>=2.0.0
|
|
28
|
+
Requires-Dist: python-dateutil>=2.8.2
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# beancount-cli
|
|
32
|
+
|
|
33
|
+
A robust command-line interface and Python library for programmatically managing [Beancount](https://beancount.github.io/) ledgers. Designed for AI agents and automation workflows.
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- **Validation**: Wrap `bean-check` to validate ledgers programmatically.
|
|
38
|
+
- **Visualization**: View the file inclusion tree (`tree` command).
|
|
39
|
+
- **Transactions**:
|
|
40
|
+
- List transactions with regex filtering (account, payee, tags).
|
|
41
|
+
- Add transactions via CLI arguments or JSON (stdin supported).
|
|
42
|
+
- Draft mode support (flag `!`).
|
|
43
|
+
- **Entities**:
|
|
44
|
+
- Manage Accounts (list, create).
|
|
45
|
+
- Manage Commodities (create).
|
|
46
|
+
- Manage Prices (fetch, update).
|
|
47
|
+
- **Formatting**:
|
|
48
|
+
- Auto-format ledgers (`bean-format` wrapper).
|
|
49
|
+
- Global output formatting: `--format` support (`table`, `json`, `csv`) for all data commands.
|
|
50
|
+
- **Reporting**: Generate balance, holding, and audit reports with multi-currency conversion.
|
|
51
|
+
- **Composability**: Built for Unix piping (`json` | `csv`) and batch processing via STDIN.
|
|
52
|
+
- **Configuration**: Custom Beancount directives for routing new entries to specific files.
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
Install using `uv` or `pip`:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
uv pip install beancount-cli
|
|
60
|
+
# or
|
|
61
|
+
pip install beancount-cli
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
For development:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
uv sync
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
### Global Formatting Flag
|
|
73
|
+
|
|
74
|
+
All data-retrieval and reporting commands support the `--format` flag.
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Default human-readable table
|
|
78
|
+
bean report bs
|
|
79
|
+
|
|
80
|
+
# Machine-readable CSV (highly token-efficient for AI agents)
|
|
81
|
+
bean --format csv transaction list
|
|
82
|
+
|
|
83
|
+
# Structural JSON (perfect for piping into jq or other scripts)
|
|
84
|
+
bean --format json account list
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Check Ledger
|
|
88
|
+
|
|
89
|
+
Validate your ledger file:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
bean check main.beancount
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Format Ledger
|
|
96
|
+
|
|
97
|
+
Format your ledger file in-place (uses `bean-format`):
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
bean format main.beancount
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### View Inclusion Tree
|
|
104
|
+
|
|
105
|
+
Visualize the tree of included files:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
bean tree main.beancount
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Reports
|
|
112
|
+
|
|
113
|
+
Generate specialized accounting reports with multi-currency support:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# Balance Sheet (Assets, Liabilities, Equity)
|
|
117
|
+
bean report balance-sheet main.beancount
|
|
118
|
+
|
|
119
|
+
# Trial Balance (All accounts including Income/Expenses)
|
|
120
|
+
bean report trial-balance main.beancount
|
|
121
|
+
|
|
122
|
+
# Holdings (Net worth per Asset account)
|
|
123
|
+
bean report holdings main.beancount
|
|
124
|
+
|
|
125
|
+
# Audit a specific currency (Source of Exposure)
|
|
126
|
+
bean report audit USD main.beancount
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
> [!TIP]
|
|
130
|
+
> Convenience aliases are supported: `bs` (balance-sheet) and `trial` (trial-balance).
|
|
131
|
+
|
|
132
|
+
#### Unified Currency Reporting
|
|
133
|
+
|
|
134
|
+
Use the `--convert` and `--valuation` flags for a consolidated view:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
# View Trial Balance in USD using historical cost
|
|
138
|
+
bean report trial main.beancount --convert USD --valuation cost
|
|
139
|
+
|
|
140
|
+
# View Balance Sheet in EUR using current market prices
|
|
141
|
+
bean report bs main.beancount --convert EUR --valuation market
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
| Valuation | Description | Use Case |
|
|
145
|
+
| :--- | :--- | :--- |
|
|
146
|
+
| `market` (default) | Uses latest prices from the ledger. | Current **Net Worth** tracking. |
|
|
147
|
+
| `cost` | Uses historical price basis (`{}`). | **Accounting Verification** (proving balance). |
|
|
148
|
+
|
|
149
|
+
**List Transactions:**
|
|
150
|
+
```bash
|
|
151
|
+
bean transaction list main.beancount --account "Assets:US:.*" --payee "Amazon"
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Add Transaction:**
|
|
155
|
+
```bash
|
|
156
|
+
# JSON via argument
|
|
157
|
+
bean transaction add main.beancount --json '{"date": "2023-10-27", ...}'
|
|
158
|
+
|
|
159
|
+
# JSON via stdin (Recommended for complex data)
|
|
160
|
+
cat tx.json | bean transaction add main.beancount --json -
|
|
161
|
+
|
|
162
|
+
# Create as Draft (!)
|
|
163
|
+
bean transaction add main.beancount --json ... --draft
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Manage Accounts & Commodities
|
|
167
|
+
|
|
168
|
+
All creation commands (`transaction add`, `account create`, `commodity create`) support batch processing via JSON arrays on STDIN.
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# Batch add transactions from a file
|
|
172
|
+
cat txs.json | bean transaction add --json -
|
|
173
|
+
|
|
174
|
+
# Pipe accounts from one ledger to another
|
|
175
|
+
bean --format json account list --file old.beancount | bean account create --json -
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Standard CLI usage:**
|
|
179
|
+
```bash
|
|
180
|
+
# List Accounts
|
|
181
|
+
bean account list
|
|
182
|
+
|
|
183
|
+
# Create Account
|
|
184
|
+
bean account create --name "Assets:NewBank" --currency "USD"
|
|
185
|
+
|
|
186
|
+
# Create Commodity
|
|
187
|
+
bean commodity create "BTC" --name "Bitcoin"
|
|
188
|
+
|
|
189
|
+
# Fetch and Update Prices
|
|
190
|
+
bean price --update
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`beancount-cli` is specifically optimized for AI agents, providing both operational guidance and machine-readable interfaces.
|
|
194
|
+
|
|
195
|
+
### Agent Documentation
|
|
196
|
+
We provide specialized documentation for different types of AI interactions:
|
|
197
|
+
- [**AGENTS.md**](./AGENTS.md): Guide for **AI End Agents** operating the CLI (prompting strategies, token optimization, batch workflows).
|
|
198
|
+
- [**CODING_AGENTS.md**](./CODING_AGENTS.md): Mandatory rules for **AI Coding Agents** modifying the source code (Value Objects, Fail-Fast rules, type safety).
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
### Transaction Schema
|
|
202
|
+
Agents can dynamically retrieve the JSON schema for transactions to ensure valid data generation:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
bean transaction schema
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Complex Transaction Example
|
|
209
|
+
Agents should aim to generate JSON in this format for a standard purchase with multiple postings:
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"date": "2023-10-27",
|
|
214
|
+
"payee": "Amazon",
|
|
215
|
+
"narration": "Office supplies",
|
|
216
|
+
"postings": [
|
|
217
|
+
{
|
|
218
|
+
"account": "Expenses:Office:Supplies",
|
|
219
|
+
"units": { "number": 45.99, "currency": "USD" }
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"account": "Liabilities:US:Chase:Slate",
|
|
223
|
+
"units": { "number": -45.99, "currency": "USD" }
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Scripting with `uv run`
|
|
230
|
+
For reliable cross-platform execution in agent workflows:
|
|
231
|
+
```bash
|
|
232
|
+
uv run bean transaction add --json - < tx.json
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Configuration
|
|
236
|
+
|
|
237
|
+
### Ledger Discovery
|
|
238
|
+
`bean` uses a 4-tier discovery logic to find your ledger file automatically:
|
|
239
|
+
1. **Explicit Argument**: Passing the filename directly (e.g. `bean check my.beancount`).
|
|
240
|
+
2. **`BEANCOUNT_FILE`**: Direct path to a ledger file.
|
|
241
|
+
3. **`BEANCOUNT_PATH`**: Looks for `main.beancount` inside this directory.
|
|
242
|
+
4. **Local Directory**: Fallback to `./main.beancount`.
|
|
243
|
+
|
|
244
|
+
### Custom Directives
|
|
245
|
+
You can configure where new entries are written using custom directives in your Beancount file.
|
|
246
|
+
|
|
247
|
+
**Note:** `custom` directives require a date (e.g. `2023-01-01`).
|
|
248
|
+
|
|
249
|
+
```beancount
|
|
250
|
+
2023-01-01 custom "cli-config" "new_transaction_file" "inbox.beancount"
|
|
251
|
+
2023-01-01 custom "cli-config" "new_account_file" "accounts.beancount"
|
|
252
|
+
2023-01-01 custom "cli-config" "new_commodity_file" "commodities.beancount"
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
**Context-Aware Insertion:**
|
|
256
|
+
You can use placeholders to route transactions to dynamic paths:
|
|
257
|
+
|
|
258
|
+
```beancount
|
|
259
|
+
2023-01-01 custom "cli-config" "new_transaction_file" "{year}/{month}/txs.beancount"
|
|
260
|
+
```
|
|
261
|
+
Supported placeholders: `{year}`, `{month}`, `{day}`, `{payee}`, `{slug}`.
|
|
262
|
+
|
|
263
|
+
**Directory Mode (One file per transaction):**
|
|
264
|
+
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.
|
|
265
|
+
|
|
266
|
+
```beancount
|
|
267
|
+
2023-01-01 custom "cli-config" "new_transaction_file" "inbox/"
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Development
|
|
271
|
+
|
|
272
|
+
Run tests:
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
uv run pytest
|
|
276
|
+
```
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# beancount-cli
|
|
2
|
+
|
|
3
|
+
A robust command-line interface and Python library for programmatically managing [Beancount](https://beancount.github.io/) ledgers. Designed for AI agents and automation workflows.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Validation**: Wrap `bean-check` to validate ledgers programmatically.
|
|
8
|
+
- **Visualization**: View the file inclusion tree (`tree` command).
|
|
9
|
+
- **Transactions**:
|
|
10
|
+
- List transactions with regex filtering (account, payee, tags).
|
|
11
|
+
- Add transactions via CLI arguments or JSON (stdin supported).
|
|
12
|
+
- Draft mode support (flag `!`).
|
|
13
|
+
- **Entities**:
|
|
14
|
+
- Manage Accounts (list, create).
|
|
15
|
+
- Manage Commodities (create).
|
|
16
|
+
- Manage Prices (fetch, update).
|
|
17
|
+
- **Formatting**:
|
|
18
|
+
- Auto-format ledgers (`bean-format` wrapper).
|
|
19
|
+
- Global output formatting: `--format` support (`table`, `json`, `csv`) for all data commands.
|
|
20
|
+
- **Reporting**: Generate balance, holding, and audit reports with multi-currency conversion.
|
|
21
|
+
- **Composability**: Built for Unix piping (`json` | `csv`) and batch processing via STDIN.
|
|
22
|
+
- **Configuration**: Custom Beancount directives for routing new entries to specific files.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
Install using `uv` or `pip`:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
uv pip install beancount-cli
|
|
30
|
+
# or
|
|
31
|
+
pip install beancount-cli
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For development:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
uv sync
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
### Global Formatting Flag
|
|
43
|
+
|
|
44
|
+
All data-retrieval and reporting commands support the `--format` flag.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Default human-readable table
|
|
48
|
+
bean report bs
|
|
49
|
+
|
|
50
|
+
# Machine-readable CSV (highly token-efficient for AI agents)
|
|
51
|
+
bean --format csv transaction list
|
|
52
|
+
|
|
53
|
+
# Structural JSON (perfect for piping into jq or other scripts)
|
|
54
|
+
bean --format json account list
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Check Ledger
|
|
58
|
+
|
|
59
|
+
Validate your ledger file:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
bean check main.beancount
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Format Ledger
|
|
66
|
+
|
|
67
|
+
Format your ledger file in-place (uses `bean-format`):
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
bean format main.beancount
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### View Inclusion Tree
|
|
74
|
+
|
|
75
|
+
Visualize the tree of included files:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
bean tree main.beancount
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Reports
|
|
82
|
+
|
|
83
|
+
Generate specialized accounting reports with multi-currency support:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Balance Sheet (Assets, Liabilities, Equity)
|
|
87
|
+
bean report balance-sheet main.beancount
|
|
88
|
+
|
|
89
|
+
# Trial Balance (All accounts including Income/Expenses)
|
|
90
|
+
bean report trial-balance main.beancount
|
|
91
|
+
|
|
92
|
+
# Holdings (Net worth per Asset account)
|
|
93
|
+
bean report holdings main.beancount
|
|
94
|
+
|
|
95
|
+
# Audit a specific currency (Source of Exposure)
|
|
96
|
+
bean report audit USD main.beancount
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
> [!TIP]
|
|
100
|
+
> Convenience aliases are supported: `bs` (balance-sheet) and `trial` (trial-balance).
|
|
101
|
+
|
|
102
|
+
#### Unified Currency Reporting
|
|
103
|
+
|
|
104
|
+
Use the `--convert` and `--valuation` flags for a consolidated view:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# View Trial Balance in USD using historical cost
|
|
108
|
+
bean report trial main.beancount --convert USD --valuation cost
|
|
109
|
+
|
|
110
|
+
# View Balance Sheet in EUR using current market prices
|
|
111
|
+
bean report bs main.beancount --convert EUR --valuation market
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
| Valuation | Description | Use Case |
|
|
115
|
+
| :--- | :--- | :--- |
|
|
116
|
+
| `market` (default) | Uses latest prices from the ledger. | Current **Net Worth** tracking. |
|
|
117
|
+
| `cost` | Uses historical price basis (`{}`). | **Accounting Verification** (proving balance). |
|
|
118
|
+
|
|
119
|
+
**List Transactions:**
|
|
120
|
+
```bash
|
|
121
|
+
bean transaction list main.beancount --account "Assets:US:.*" --payee "Amazon"
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Add Transaction:**
|
|
125
|
+
```bash
|
|
126
|
+
# JSON via argument
|
|
127
|
+
bean transaction add main.beancount --json '{"date": "2023-10-27", ...}'
|
|
128
|
+
|
|
129
|
+
# JSON via stdin (Recommended for complex data)
|
|
130
|
+
cat tx.json | bean transaction add main.beancount --json -
|
|
131
|
+
|
|
132
|
+
# Create as Draft (!)
|
|
133
|
+
bean transaction add main.beancount --json ... --draft
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Manage Accounts & Commodities
|
|
137
|
+
|
|
138
|
+
All creation commands (`transaction add`, `account create`, `commodity create`) support batch processing via JSON arrays on STDIN.
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# Batch add transactions from a file
|
|
142
|
+
cat txs.json | bean transaction add --json -
|
|
143
|
+
|
|
144
|
+
# Pipe accounts from one ledger to another
|
|
145
|
+
bean --format json account list --file old.beancount | bean account create --json -
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Standard CLI usage:**
|
|
149
|
+
```bash
|
|
150
|
+
# List Accounts
|
|
151
|
+
bean account list
|
|
152
|
+
|
|
153
|
+
# Create Account
|
|
154
|
+
bean account create --name "Assets:NewBank" --currency "USD"
|
|
155
|
+
|
|
156
|
+
# Create Commodity
|
|
157
|
+
bean commodity create "BTC" --name "Bitcoin"
|
|
158
|
+
|
|
159
|
+
# Fetch and Update Prices
|
|
160
|
+
bean price --update
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
`beancount-cli` is specifically optimized for AI agents, providing both operational guidance and machine-readable interfaces.
|
|
164
|
+
|
|
165
|
+
### Agent Documentation
|
|
166
|
+
We provide specialized documentation for different types of AI interactions:
|
|
167
|
+
- [**AGENTS.md**](./AGENTS.md): Guide for **AI End Agents** operating the CLI (prompting strategies, token optimization, batch workflows).
|
|
168
|
+
- [**CODING_AGENTS.md**](./CODING_AGENTS.md): Mandatory rules for **AI Coding Agents** modifying the source code (Value Objects, Fail-Fast rules, type safety).
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
### Transaction Schema
|
|
172
|
+
Agents can dynamically retrieve the JSON schema for transactions to ensure valid data generation:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
bean transaction schema
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Complex Transaction Example
|
|
179
|
+
Agents should aim to generate JSON in this format for a standard purchase with multiple postings:
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"date": "2023-10-27",
|
|
184
|
+
"payee": "Amazon",
|
|
185
|
+
"narration": "Office supplies",
|
|
186
|
+
"postings": [
|
|
187
|
+
{
|
|
188
|
+
"account": "Expenses:Office:Supplies",
|
|
189
|
+
"units": { "number": 45.99, "currency": "USD" }
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"account": "Liabilities:US:Chase:Slate",
|
|
193
|
+
"units": { "number": -45.99, "currency": "USD" }
|
|
194
|
+
}
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Scripting with `uv run`
|
|
200
|
+
For reliable cross-platform execution in agent workflows:
|
|
201
|
+
```bash
|
|
202
|
+
uv run bean transaction add --json - < tx.json
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Configuration
|
|
206
|
+
|
|
207
|
+
### Ledger Discovery
|
|
208
|
+
`bean` uses a 4-tier discovery logic to find your ledger file automatically:
|
|
209
|
+
1. **Explicit Argument**: Passing the filename directly (e.g. `bean check my.beancount`).
|
|
210
|
+
2. **`BEANCOUNT_FILE`**: Direct path to a ledger file.
|
|
211
|
+
3. **`BEANCOUNT_PATH`**: Looks for `main.beancount` inside this directory.
|
|
212
|
+
4. **Local Directory**: Fallback to `./main.beancount`.
|
|
213
|
+
|
|
214
|
+
### Custom Directives
|
|
215
|
+
You can configure where new entries are written using custom directives in your Beancount file.
|
|
216
|
+
|
|
217
|
+
**Note:** `custom` directives require a date (e.g. `2023-01-01`).
|
|
218
|
+
|
|
219
|
+
```beancount
|
|
220
|
+
2023-01-01 custom "cli-config" "new_transaction_file" "inbox.beancount"
|
|
221
|
+
2023-01-01 custom "cli-config" "new_account_file" "accounts.beancount"
|
|
222
|
+
2023-01-01 custom "cli-config" "new_commodity_file" "commodities.beancount"
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**Context-Aware Insertion:**
|
|
226
|
+
You can use placeholders to route transactions to dynamic paths:
|
|
227
|
+
|
|
228
|
+
```beancount
|
|
229
|
+
2023-01-01 custom "cli-config" "new_transaction_file" "{year}/{month}/txs.beancount"
|
|
230
|
+
```
|
|
231
|
+
Supported placeholders: `{year}`, `{month}`, `{day}`, `{payee}`, `{slug}`.
|
|
232
|
+
|
|
233
|
+
**Directory Mode (One file per transaction):**
|
|
234
|
+
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.
|
|
235
|
+
|
|
236
|
+
```beancount
|
|
237
|
+
2023-01-01 custom "cli-config" "new_transaction_file" "inbox/"
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Development
|
|
241
|
+
|
|
242
|
+
Run tests:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
uv run pytest
|
|
246
|
+
```
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "beancount-cli"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "A CLI tool to manage Beancount ledgers"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Roman Medvedev", email = "pypi@romavm.dev" }
|
|
8
|
+
]
|
|
9
|
+
license = { text = "MIT" }
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"beancount>=3.0.0",
|
|
13
|
+
"beanquery>=0.1.0",
|
|
14
|
+
"pydantic>=2.0.0",
|
|
15
|
+
"python-dateutil>=2.8.2",
|
|
16
|
+
"beanprice>=2.1.0",
|
|
17
|
+
"pydantic-settings>=2.0.0",
|
|
18
|
+
]
|
|
19
|
+
keywords = ["beancount", "cli", "accounting", "automation", "agent"]
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Development Status :: 3 - Alpha",
|
|
22
|
+
"Environment :: Console",
|
|
23
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
24
|
+
"License :: OSI Approved :: MIT License",
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Programming Language :: Python :: 3.10",
|
|
27
|
+
"Programming Language :: Python :: 3.11",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Programming Language :: Python :: 3.13",
|
|
30
|
+
"Topic :: Office/Business :: Financial :: Accounting",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/romamo/beancount-cli"
|
|
35
|
+
Repository = "https://github.com/romamo/beancount-cli"
|
|
36
|
+
Issues = "https://github.com/romamo/beancount-cli/issues"
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
bean = "beancount_cli.cli:main"
|
|
40
|
+
|
|
41
|
+
[tool.hatch.build.targets.sdist]
|
|
42
|
+
include = [
|
|
43
|
+
"src/beancount_cli",
|
|
44
|
+
"tests",
|
|
45
|
+
"CHANGELOG.md",
|
|
46
|
+
"README.md",
|
|
47
|
+
"LICENSE",
|
|
48
|
+
]
|
|
49
|
+
exclude = [
|
|
50
|
+
".agent",
|
|
51
|
+
".github",
|
|
52
|
+
"uv.lock",
|
|
53
|
+
"tmp",
|
|
54
|
+
"dist",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[tool.hatch.build.targets.wheel]
|
|
58
|
+
packages = ["src/beancount_cli"]
|
|
59
|
+
|
|
60
|
+
[build-system]
|
|
61
|
+
requires = ["hatchling"]
|
|
62
|
+
build-backend = "hatchling.build"
|
|
63
|
+
|
|
64
|
+
[dependency-groups]
|
|
65
|
+
dev = [
|
|
66
|
+
"bandit>=1.8.6",
|
|
67
|
+
"mypy>=1.19.1",
|
|
68
|
+
"pytest>=8.0.0",
|
|
69
|
+
"pytest-cov>=4.0.0",
|
|
70
|
+
"ruff>=0.9.2",
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
[tool.ruff]
|
|
74
|
+
line-length = 100
|
|
75
|
+
target-version = "py310"
|
|
76
|
+
|
|
77
|
+
[tool.ruff.lint]
|
|
78
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
79
|
+
ignore = []
|
|
80
|
+
|
|
81
|
+
[tool.ruff.lint.per-file-ignores]
|
|
82
|
+
"tests/*" = ["E501"]
|
|
83
|
+
|
|
84
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.0"
|