Skip to main content

Library to import bank transactions via API into You Need A Budget (YNAB)

Project description

ynab-api-import

GitHub Release

This library enables importing YNAB transactions via the Gocardless Bank Account Data API (formerly Nordigen). It can be 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 and their institution_ids. Find and save the institution_id of your bank.

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

3. Create Auth Link and authenticate with your bank

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

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>')

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 dict for inspection

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

prints and returns a list with following content

[{original_memo: cleaned_memo}]

Development

Read the CONTRIBUTING.md file.

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_api_import-0.5.1.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

ynab_api_import-0.5.1-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file ynab_api_import-0.5.1.tar.gz.

File metadata

  • Download URL: ynab_api_import-0.5.1.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Linux/6.2.0-1019-azure

File hashes

Hashes for ynab_api_import-0.5.1.tar.gz
Algorithm Hash digest
SHA256 ed4368f6ba29b78f2a145d55ba179f7394b510ebfe7a4dae78c428994ec9a803
MD5 62f8cc8d5ab22280f89d3d00e5c3f062
BLAKE2b-256 e80ca38a63e7f6a8a79a5f1b8fc7af42072e2cd797b1985b5e58fc13ac85b949

See more details on using hashes here.

File details

Details for the file ynab_api_import-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: ynab_api_import-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Linux/6.2.0-1019-azure

File hashes

Hashes for ynab_api_import-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a00a89a465da8f4eda0158e61446e9207ba3584c7bd24e8aae94066616150e7
MD5 aa6494f6acf9747ff69565cef3f0e5d3
BLAKE2b-256 7076a3ca3f652c930ef5547045d97fd87c33993ed18ae31b4c427bfa1d76ae39

See more details on using hashes here.

Supported by

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