Skip to main content

Library to automatically adjust transactions in YNAB based on your logic in simple factory class

Project description

ynab-transaction-adjuster

GitHub Release Github Release

This library helps you to automatically adjust transactions in YNAB based on your logic. It allows you to implement your adjustments in a simple factory class which you can run against your existing transactions and update relevant fields like date, payee, category, memo and flags. It also allows you to split transactions.

"Buy Me A Coffee"

Preparations

  1. Create a personal access token for YNAB as described here
  2. 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>

Installation

Install library from PyPI

pip install ynab-transaction-adjuster

Usage

A detailed documentation is available at https://ynab-transaction-adjuster.readthedocs.io

Fetch transactions

Fetch current transactions from YNAB backend with all available information and check for useful values. All records come with two additional attributes (import_payee_name and import_payee_name_original) which are not shown in the user interface.

from ynabtransactionadjuster import YnabTransactionAdjuster

ynab_transaction_adjuster = YnabTransactionAdjuster(token='<token>',
													budget='<budget>',
													account='<account>')
orig_transactions = ynab_transaction_adjuster.fetch()

Create a AdjusterFactory child class

This class is for implementing your actual logic. It needs to implement a run() method which receives on runtime the OriginalTransaction and a TransactionModifier. The latter is prefilled with values from the original transaction. Its attributes can be modified and it needs to be returned at the end of the function.

from ynabtransactionadjuster import AdjusterFactory
from ynabtransactionadjuster.models import OriginalTransaction, TransactionModifier


class MyAdjusterFactory(AdjusterFactory):

	def run(self, original: OriginalTransaction, modifier: TransactionModifier) -> TransactionModifier:
		# your implementation

		# return the altered modifier
		return modifier

Test your Factory class

Test the factory on records fetched via the fetch()method. If only a subset of these transactions should get adjusted, filter them before handing the list over to the adjust() method. The method returns a list of ModifiedTransaction objects which can be inspected for the changed properties.

transations = ynab_transaction_adjuster.fetch()
# optionally filter transactions before passing them to method below
mod_transactions = ynab_transaction_adjuster.adjust(transactions=transactions,
													factory_class=MyAdjusterFactory)

Update records in YNAB

If you are satisfied with your parsing results you can pass the list of the ModifedTransaction objects to the update() method. It will update
the changed transactions in YNAB and return an integer with the number of successfully updated records.

count = ynab_transaction_adjuster.update(transactions=mod_transactions)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ynab_transaction_adjuster-0.1.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ynab_transaction_adjuster-0.1.0-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

Details for the file ynab_transaction_adjuster-0.1.0.tar.gz.

File metadata

  • Download URL: ynab_transaction_adjuster-0.1.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/6.5.0-1016-azure

File hashes

Hashes for ynab_transaction_adjuster-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e1b0d41ca2af9550a1f0a34944a6684e5f17c87a42fbdc9b27e9e028722a01cd
MD5 940dfdc4cf87bf60fe1fb409dcda1357
BLAKE2b-256 41f6eccf101247bcc1b239f37cd44de5673d00cbede5f6841307160340db157f

See more details on using hashes here.

File details

Details for the file ynab_transaction_adjuster-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ynab_transaction_adjuster-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5cd7880c7f307c58c0e94eec1862cb7b104e81eba8cb89adefbcf2ca810b20d5
MD5 1b36b3d8534d45464a33719ad47146da
BLAKE2b-256 78b767bdc1f81478605c52cc3d5518a8d4e9a6739b8505be9bcc5f3e87459c0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page