hledger-import
Convert financial data into hledger journal format
TLDR
Import new transactions from bank.csv, using bank.csv.rules to convert
Show what would be imported from these two files, without doing anything
Import new transactions from all CSV files, using the same rules for all
Show conversion errors or results while editing bank.csv.rules
Mark bank.csv's current data as seen, as if already imported
Mark bank.csv as all new, as if not yet imported
SYNOPSIS
hledger import [OPTIONS] [CSVFILE]
PARAMETERS
-f, --file JOURNAL
validate generated postings against this journal file
--rules-file FILE
read CSV parsing rules from FILE (default: CSVFILE.rules)
--values-from FILE
read field values from this CSV for rule testing/sample generation
-o, --output-file FILE
write journal output to FILE (default: stdout)
--no-new-accounts
disallow new accounts (stricter validation; default allows)
--account-transform PATTERNS
apply regex/replacements to standardise account names
--date-format STR
parse dates using this strptime format (default: %Y-%m-%d)
DESCRIPTION
hledger import converts CSV files from banks into hledger's plain text journal format. It relies on a companion rules file (default: CSVFILE.rules) defining how to parse columns into dates, descriptions, accounts, amounts, and tags.
The tool processes each transaction interactively: applies rules, shows a preview, prompts to edit or confirm details like payee/accounts, splits if needed, and verifies balance. This handles real-world CSV inconsistencies effectively. Output goes to stdout (appendable to journals) or a file.
Specify a journal with -f for validation against existing postings, ensuring consistency. Test rules with --values-from using sample data. Options control new accounts, output, and transformations.
Part of the free, open-source hledger suite, it promotes auditable, git-friendly accounting without databases. Pairs with hledger balance, print for review. Ideal for double-entry bookkeeping in text files, scriptable for automation.
CAVEATS
Interactive prompting required (use --values-from for batch testing); rules file must be crafted per CSV source; complex CSVs may need if/else rules or preprocessing; no built-in CSV sanitisation.
RULES FILE FORMAT
YAML-like syntax maps CSV fields: if ..., account ..., amount .... See hledger(1) CSV rules section for details.
Example:
currency USD
date %d/%m/%Y
account 1 "Visa" "Expenses:Credit card"
TYPICAL WORKFLOW
1. Export bank CSV.
2. Create bank.csv.rules.
3. hledger import -f journal.journal bank.csv >> journal.journal
4. Review with hledger balance.
HISTORY
Introduced in hledger 0.24 (2013) as improved csv2journal; enhanced in 1.0+ with interactive editing, validation, better rules syntax. Developed by Simon Michael since 2007.
SEE ALSO
hledger(1), hledger-balance(1), ledger(1)


