A Python script that automatically splits transactions in YNAB4 budgets.
This script modifies your YNAB budget files! I've tested it on my own files and believe it will at least do no harm. However, you use this script at your own risk and should ensure you have backups of all YNAB files before use.
You'll need to set up a config file first. There's an example named ynabsplitter.json
in the repo. These are the keys in the config file:
This is the path to your YNAB directory--the directory that contains all of your "Budget~12345678.ynab4" directories. If you're using YNAB's cloud sync, this is probably c:/Users/<you>/Dropbox/YNAB
.
Same as windowsYnabDir, but will be used on Macs.
This is the category that you'll temporarily assign to transactions that you want to be split by the script. It should follow the form "Master Category/Category". For example, my value here is "Chaff/To Split".
The name of the budget you want to modify. This should be the name of one of the directories in your windows/macYnabDir.
This value defines how splits are made. To split transactions evenly, use 2
. To make the smaller split 1/3 of the total and the larger split 2/3, use 3
. Specifying the denominator is a bit awkward, but it works best for my personal use.
This should have the same form as toSplitCategoryPath. It specifies which category to assign to the smaller split of each transaction that's modified. To leave these splits uncategorized, use null
here.
Same as smallerSplitCategoryPath, but for the larger split.
To disable this feature, use null
. This value is useful for sending the splits to a spreadsheet. After writing the splits to the budget file, the script will copy to the clipboard one line for each modified transaction. You can specify the format of the lines here. If you had a spreadsheet for your shared expenses with someone else like this:
Date Entered | Date of Transaction | Amount | Comment |
---|---|---|---|
2017-12-10 | 2017-12-07 | 16.05 | J bought Safeway 32.10 |
You could use {date}\t{txDate}\t{splitAmount}\tJ bought {payee} {totalAmount}
for this config value. After the script ran, you could paste into the spreadsheet (copying to clipboard is done automatically) and have all the split information there, too!
In YNAB, assign all the transactions you want to be split to your "to split" category that you specified in the config file. Close YNAB and give Dropbox a few seconds to sync. Then, run the script:
./ynabsplitter.py
Watch the output for any errors. If all goes well, congratulations! You can reopen YNAB and get back to work without having to robotically split transactions.
If you want to export the split information to a spreadsheet and you specified ledgerOutputFormat in the config file, you can now paste into your spreadsheet.
The YNAB file formats and cloud sync mechanism are tough to pick up from reverse engineering. I'd like to thank the giants whose shoulders I stood on.