Skip to content

A simple library for parsing hledger journal files

License

Notifications You must be signed in to change notification settings

rmcl/ledger_reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ledger Reader

A simple parser for hledger journal files. It's always fun to play with rply and use a simple grammar. PR's welcome :).

Install

pip install ledger-reader

Example usage

Read a journal

from ledger_reader import LedgerReader

reader = LedgerReader()
journal = reader.parse_file('bank.journal')

for entry in journal:
    print(entry.date, entry.description)
    for transaction in entry.transactions:
        print(f'{transaction.account} {transaction.currency} {transaction.amount}')

    print()

Append to a journal

from datetime import date
from ledger_reader import Entry, Transaction

entry = Entry(
    date(2022, 3, 5),
    'Cash Transfer',
    transactions=[
        Transaction('assets:bank:boa:checking', '$', -5000),
        Transaction('assets:bank:boa:savings')
    ]
)

with open('bank.journal', 'a') as fp:
    fp.write(f'\n{entry}')

About

A simple library for parsing hledger journal files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages