This library helps you to use original memo and payee information from your bank transactions to either show additional details or substitute/change the current one in YNAB. It can be helpful for cases in which YNAB import does not handle the information coming from the bank well (e.g. not showing the actual bank memo or populating a wrong payee name).
NOTE: Consider using the ynab-transaction-adjuster library instead of this one. It can do the same and more
- Create a personal access token for YNAB as described here
- Get the IDs of your budget and account which records are faulty. You can find both IDs if you go to
https://app.ynab.com/ and open the target account by clicking on the name on the left hand side menu.
The URL does now contain both IDs
https://app.ynab.com/<budget_id>/accounts/<account_id>
pip install ynab-memo-parser
All records in YNAB come with their original memo and payee information attached. You can see both values if you use the `fetch records' function of this library and look at a couple sample records.
from ynabmemoparser import YnabMemoParser
ynab_memo_parser = YnabMemoParser(token='<token>', budget='<budget>', account='<account>')
ynab_memo_parser.fetch_record_dicts()
You will get back a dictionary with all data stored for the transaction. The library uses the following keys with the stated labels
import_payee_name_original
asoriginal_memo
import_payee_name
asoriginal_payee
payee
ascurrent_payee
memo
ascurrent_memo
The class needs to implement a logic for parse_payee()
and parse_memo()
based on the values coming from the four
fields above. If you don't want to change anything in the field you e.g. just return current_payee
inside the
parse_payee()
function.
from ynabmemoparser import Parser
class MyParser(Parser):
def parse_payee(self, original_payee: str, current_payee: str, original_memo: str, current_memo: str) -> str:
# your implementation
def parse_memo(self, original_payee: str, current_payee: str, original_memo: str, current_memo: str) -> str:
# your implementation
from ynabmemoparser import YnabMemoParser
ynab_memo_parser = YnabMemoParser(token='<token>', budget='<budget>', account='<account>')
record_dicts = ynab_memo_parser.fetch_record_dicts()
parsed_records = ynab_memo_parser.parse_records(records_dicts=record_dicts, parser=MyParser())
You will get back a list of YnabRecord
objects. Check the payee
and memo
fields in these objects to see the result
of your parser.
If you are satisfied with your parsing results you can pass the list of YnabRecord
to the update_records()
function.
It will update the payee
and memo
values in YNAB with the values in the YnabRecord
object
ynab_memo_parser.update_records(parsed_records)
If the insert is successful you get back an integer with the number of records which have been updated.