AtlatestRepositorysigil-ledger
sigil-ledger / treeREADME.md
1
# sigil-ledger3
A Sigil library for reading, writing, and querying [hledger](https://hledger.org) journal files. Build financial automation tools that work with plain-text accounting.5
## Features7
- **Journal parsing** — read hledger journal files into structured records (transactions, postings, amounts, commodities, tags)8
- **Journal writing** — write and append transactions in valid hledger format9
- **Multi-currency** — full support for cost notation (`@` and `@@`) and balance assertions10
- **Deduplication** — filter out already-imported transactions by reference ID tag11
- **Report generation** — run hledger CLI commands (balance, register, income statement) and parse output12
- **Round-trip fidelity** — parse and re-serialize journals without losing information14
## Usage16
```scheme17
(import (ledger))19
;; Parse a journal file20
(define txns (read-journal "/path/to/finances.journal"))22
;; Create a new transaction23
(define txn (journal-transaction24
date: "2026-03-25"25
status: "*"26
description: "Coffee Shop"27
postings: (list28
(journal-posting29
account: "expenses:food:coffee"30
amount: (journal-amount quantity: 4.50 commodity: "EUR"))31
(journal-posting32
account: "assets:wise:eur"))))34
;; Append new transactions to journal35
(append-transactions "/path/to/finances.journal" (list txn))36
```38
### Reports via hledger CLI40
```scheme41
(import (ledger report))43
;; Run a balance report44
(hledger-balance "/path/to/finances.journal" "assets" tree: #t)46
;; Income statement for a period47
(hledger-income-statement "/path/to/finances.journal" period: "2026-03")48
```50
## Journal Format Support52
Handles standard hledger journal syntax:53
- Dates, status flags (`*`, `!`), transaction codes54
- Payee/note separator (`|`)55
- Account names with amounts and commodities56
- Inline and line comments (`;`)57
- Tags in comments (`tag:value`)58
- Cost notation (`@ PRICE` and `@@ TOTAL`)59
- Balance assertions (`= AMOUNT`, `== AMOUNT`, `=* AMOUNT`)61
## Known Limitations63
- **European number format** — amounts using period as thousands separator and comma as decimal separator (e.g. `1.000,50 EUR`) are not supported. Use US-style formatting (`1,000.50 EUR`) or omit thousands separators. This matches the most common hledger usage; full `decimal-mark` directive support may be added in a future release.65
## Dependencies67
- sigil-stdlib68
- sigil-json (for hledger JSON output parsing)70
Requires `hledger` on PATH for report generation features.72
## Building74
```bash75
sigil deps install76
sigil build77
sigil test78
```80
## License82
BSD-3-Clause