Skip to main content

ynab-api-import

GitHub Release Github Release Monthly downloads

"Buy Me A Coffee"

This library enables importing YNAB transactions via the Gocardless Bank Account Data API (formerly Nordigen). It is pretty helpful for cases in which your bank is not covered by YNABs native import functionality.

Preparations

Gocardless Bank Account API (formerly Nordigen)

  1. Check if your bank is supported by the API.
  2. Create an account with Gocardless for the Bank Account Data API (They have a separate Login for it which you can get to by clicking on 'Get API Keys' or clicking the link at the bottom of their standard login page)
  3. Go to Developers -> User Secrets and create a new pair of secret_id and secret_key

YNAB

  1. Create a personal access token for YNAB as described here

Basic Usage

1. Install library from PyPI

pip install ynab-api-import

2. Initiate Library

Provide a unique reference (e.g. 'mycheckingaccount') per bank connection to identify the grant later on. You can find the IDs of your budget and the account 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>

from ynabapiimport import YnabApiImport
ynab_api_import = YnabApiImport(secret_id='<secret_id>', 
                                secret_key='<secret_key>',
                                reference='<reference>',
                                token='<ynab_token>',
                                budget_id='<budget_id>',
                                account_id='<account_id>')

Optionally you can initiate an object from a config.yaml file. To do that create a YAML file with the following content:

secret_id: <secret_id>
secret_key: <secret_key>
reference: <reference>
token: <ynab_token>
budget_id: <budget_id>
account_id: <account_id>

Save the file and provide the path to the library when initializing

ynab_api_import = YnabApiImport.from_yaml('path/to/config.yaml')

2. Find the institution_id of your bank

Countrycode is ISO 3166 two-character country code.

ynab_api_import.fetch_institutions(countrycode='<countrycode>')

You get back a dictionary with all available banks in that country, their institution_ids and the maximum days of transaction history provided by the bank. Find and save the institution_id of your bank.

[{'name': '<name>', 'institution_id': '<institution_id>', 'max_history_days': 'ddd'}]

Provide the institution_id. You get back a link which you need to copy to your browser and go through authentication flow with your bank. By default, the authorization will allow you to fetch 90 days of your transaction history. You can set the option use_max_historical_days to True in order to fetch longer transaction history. This is known to cause issues sometimes, so in case you get an 500 error from the Gocardless API try an authorization with default 90 days.

ynab_api_import.create_auth_link(institution_id='<institution_id>')

4. Run import with your reference and YNAB identifiers

Optionally you can provide a startdate argument in form of a datetime.date object to only import transactions from a specific date onwards. Equally optionally you can provide a memo_regex argument in from of a regex string to the call to clean the memo string before importing into YNAB. A good helper to write your regex is
https://regex101.com

ynab_api_import.import_transactions()

Advanced Usage

Handling of multiple accounts in your bank connection (MultipleAccountsError)

The library assumes that you have one active account in your bank connection. It will raise an error if there are no accounts in your connection or more than one. In the latter case you need to provide the correct resource_id when initializing the library. You can find the resource_id by looking into the available options in the error message.

from ynabapiimport import YnabApiImport
ynab_api_import = YnabApiImport(resource_id='<resource_id>',
                                secret_id='<secret_id>', 
                                secret_key='<secret_key>',
                                reference='<reference>',
                                token='<ynab_token>',
                                budget_id='<budget_id>',
                                account_id='<account_id>')

Compare balances

This method will fetch the available balance variants for your account from the API and compare them to the balance in YNAB. It compares the plain balance values as well as the balances minus the sum of still pending transactions. If none of them match it raises a BalancesDontMatchError

ynab_api_import.compare_balances()

Delete current bank authorization

By default you can create only one bank authorization per reference. If you need to replace the authorization under your current reference you can explicitly do that by setting the delete_current_auth option when creating an auth link.

ynab_api_import.create_auth_link(institution_id='<institution_id>', delete_current_auth=True)

Show Logs

The library logs information about the result of the methods on the 'INFO' level. If you want to see these logs import the logging module and set it to the level INFO. You can also access the logger for advanced configuration via the logger attribute of your YnabApiImportinstance.

import logging

logging.basicConfig(level='INFO')

Testing your memo_regex

You can test your memo_regex with a call to test_memo_regex(). The function will fetch transactions from your bank account, apply the regex and output the old and new memo strings in a dictionary for inspection.

ynab_api_import.test_memo_regex(memo_regex=r'<memo_regex')

returns a list of dict with following content

[{original_memo: cleaned_memo}]

Metadata

Release files for ynab-api-import 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ynab-api-import 2.0.0
File Size Uploaded
ynab_api_import-2.0.0.tar.gz 22.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ynab-api-import 2.0.0
File Interpreter ABI Platform
ynab_api_import-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 46.3 kB

Release files / ynab_api_import-2.0.0.tar.gz

Download URL ynab_api_import-2.0.0.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
017a10645b511d1adbbd0c7684f7cd94049a298fbc17e248a597ece5c4324414
BLAKE2b-256 checksum
How to use checksums
3b8d19502413b8b9fce9aed8ee803a3dd89bd9147826f362fa1af5ec42fa4f35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

Release files / ynab_api_import-2.0.0-py3-none-any.whl

Download URL ynab_api_import-2.0.0-py3-none-any.whl
Size 23.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d194d3e0a24b5e28839c23a7de30ffb4df6ff6a94dd3b2ef3d6ddf72bac0a380
BLAKE2b-256 checksum
How to use checksums
1d3366e0414dba5e4fdef7137364edcef17cf20703c1037b232bff869261888a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page