Package: ledger-importer
ledger_importerledger_importer is a csv-to-ledgerimporter that can be configured in Python.The key features are:Customization: Designed to fit your specific needs perfectly.Auto-completion: The confirmation step is auto-completed.Integration: Easy to integrate with your pipeline.ledger_importer main selling point is that if you know Python, you can write complex rules to match & parse accounts / target_accounts. All other tools try to be smart about the target_account matching part but offer very little customization (regex matching is the best I've seen).Another cool feature is that if you have several bank accounts, you can concatenate their csv exports and ledger_importer will de-duplicate transactions between them. The de-duplication rule can be customized to your needs.Installation$pipinstallledger-importerQuickstartGenerate a new config file:ledger_importerinit>my_importer.py/Optional/: update the configuration for your needs (see theConfigure section)Import your bank statementledger_importerimport--statement-pathstatement.csv--config-pathmy_importer.py::LedgerImporterConfigNote: the ledger transactions are written to stdout. Redirect stdout to your ledger journal to write them there instead (add>> journal.ledgerat the end of the previous command).Configureledger_importeris configured in Python. You can give your configuration to the ledger_importer CLI using a string ressemblingpytest node ids. For example:ledger_importer import --statement-path statement.csv --config-path ~/ledger/my_config.py::LedgerConfig.A Config instance can be created by creating a new class that inheritsledger_importer.Config. This new class must implement the following methods:parse_date(self, fields: tuple) -> datetime.datetimeparse_payee(self, fields: tuple) -> strparse_postings(self, fields: tuple) -> list[Posting]The argumentfields: tuplewill be the csv row, with each column as an element of the tuple.Example configuration file:#!/usr/bin/env pythonfrom__future__importannotationsimportdatetimeimportrefromdecimalimportDecimalfromledger_importerimportConfig,Posting,Amount# Custom ledger importer configurationclassLedgerImporterConfig(Config):# Define the number of lines that needs to be skipped at the beginning of the file.# This is usefull if the csv has a line with the column names for example.skip_lines:int=1# Define the csv delimitercsv_delimiter:str=";"# The argument `fields` given in all parse_* methods contains a whole csv row in a tuple# Each element of the tuple is a string representation of the columndefparse_date(self,fields:tuple)->datetime.datetime:returndatetime.datetime.strptime(fields[0],"%m-%d-%Y")defparse_payee(self,fields:tuple)->str:returnfields[2]defparse_postings(self,fields:tuple)->list[Posting]:amount=Amount(quantity=Decimal(re.sub("[€ ]","",fields[3]).replace(",",".")),commodity="€")ifamount>0:account="Income"else:account="Expenses"posting=Posting(account="Assets:Checking",amount=amount)# A Transaction should be at least 2 postings that have reversed amountsreturn[posting,Posting(account=account,amount=amount.reverse())]RunTo run leger_importer:$ledger_importerimport--statement-pathbank-statement.csv--journal-pathjournal.ledger--config-pathmy_importer.py::LedgerImporterConfig|Account|Date|Amount|Payee||Assets:Account:Florent|2021/07/29|1234.56€|VIRLOLEFOOBA.R.L|Whichaccountprovidedthisincome?([Income:Salary]/[q]uit/[s]kip)|Account|Date|Amount|Payee||Assets:Account:Florent|2021/08/02|-11.77€|CARD27/07/21SWILEXX*XXXX|Towhichaccountdidthismoneygo?([Expenses:Restaurant]/[q]uit/[s]kip)|Account|Date|Amount|Payee||Assets:Account:Florent|2021/08/03|-784.00€|VIRSavesome€Mr.Florent|Towhichaccountdidthismoneygo?([Expenses]/[q]uit/[s]kip)Assets:Savings|Account|Date|Amount|Payee||Assets:Account:Florent|2021/08/03|-58.63€|CARD08/03/21PAYPALXX*XXXX|Towhichaccountdidthismoneygo?([Expenses:Shopping]/[q]uit/[s]kip)qUsageRoot command:$ledger_importer--help
Usage:ledger_importer[OPTIONS]COMMAND[ARGS]...

Options:--helpShowthismessageandexit.

Commands:importImportabankstatement.initBootstrapaconfigfilethatcanlaterbecustomized.Import command imports bank statement and generates ledger transactions:$ledger_importerimport--help
Usage:ledger_importerimport[OPTIONS]Importabankstatement.

Options:--statement-pathPATHPathtothebankstatementtoimport.[required]--config-pathTEXTPythonpathtotheconfigurationfile.[required]--journal-pathPATHPathaledgerjournaltowrite&learnaccountsfrom.--quiet/--no-quietDon'taskquestionsandguessalltheaccountsautomatically.[default:no-quiet]--helpShowthismessageandexit.Init command bootstraps a new config file:$ledger_importerinit--help
Usage:ledger_importerinit[OPTIONS]Bootstrapaconfigfilethatcanlaterbecustomized.

Options:--helpShowthismessageandexit.