Gnucash2Ledger is a Python script based on the Github Gist by nonducor (nonducor/gcash2ledger.py). This Python script will take an uncompressed Gnucash file saved in the default XML format and write a text file in a format compatible with John Wiegley’s ledger program (Github: ledger/ledger).
Note: gnucash2ledger will only work if the Gnucash data is saved in an uncompressed XML file. If you prefer to save your Gnucash in SQL database formats, checkout the piecash project.
gnucash2ledger has the following features:
- Allows for export to a text file or prints results to standard output
- Exports commodity definitions, account definitions, and transactions with splits
- Supports multiple commodities/currencies
- Provides and option to insert a default header for Emacs
ledger-mode
(Github: ledger/ledger-mode) - Currency codes can be replaced by currency symbols using Python CurrencySymbols library
- Provides an option to display progress bars (useful for converting very long Gnucash files and you want to verify something is running)
Gnucash2ledger can be called with the following command:
python3 gnucash2ledger.py [-h] [-c] [-d DATE_FORMAT] [-e] [-f] [-na] [-nc] [-nt] [-o FILENAME] [-p] [--payee-metadata] [-s] [-v] INPUT_FILE
Alternatively, the following command can be used to call Gnucash2ledger if gnucash2ledger.py
has permission to run as an executable file:
gnucash2ledger.py [-h] [-c] [-d DATE_FORMAT] [-e] [-f] [-na] [-nc] [-nt] [-o FILENAME] [-p] [--payee-metadata] [-s] [-v] INPUT_FILE
Documentation of the various command line arguments can be seen in the following output from gnucash2ledger -h
:
positional arguments: input a Gnucash XML file to be read optional arguments: -h, --help show this help message and exit -c, --cleared Marks all transactions as cleared and place a cleared (*) mark before the transaction heading. -d DATE_FORMAT, --date-format DATE_FORMAT A string representing the desired format of dates in the ledger file. Defaults to the ISO standard format: '%Y-%m-%d'. -e, --emacs-header Adds a default header for ledger-mode in Emacs. -f, --force-clobber Force clobbering of and output file i the file already exists. If this option is provided, the output file will overwrite the existing file with the same name. -na, --no-account-defs Prevents output of account definitions to the output file. -nc, --no-commodity-defs Prevent output of commodities to the output file. -nt, --no-transations Prevent output of transactions to the output file. NOTE: This will cause ledger to throw an error if executed on this file. -o FILENAME, --output FILENAME Name of file to store the output results. -p, --show-progress Show script status progress while reading and writing data. --payee-metadata Takes the information entered into the 'Description' field in Gnucash splits and adds them as a tagged '; Payee:' memo for the corresponding transaction split. -s, --use-symbols Replaces currency codes with currency symbols. -v, --version show program's version number and exit
gnucash2ledger requires that the following Python packages are installed:
- currency-symbols
- tqdm
- [ ] Include options to add/remove headers for different sections
- [ ] Increase parsing speed of Gnucash XML file (consider writing a verison with Go)
- [ ] Include options for splitting large Gnucash files into multiple ledger files