Skip to main content

ynab-py

ynab-py is a Python library designed for seamless interaction with the YNAB (You Need A Budget) API. It provides a user-friendly interface to manage your budgets, accounts, transactions, and more with ease.

ynab-py currently works with YNAB's 1.72.0 API. For more information, see https://api.ynab.com/v1.

Installation

To install ynab-py from PyPI:

pip install ynab-py

Or to install from source:

git clone https://github.com/dynacylabs/ynab-py.git
cd ynab-py
python -m venv .venv
source .venv/bin/activate
pip install ./

Usage

Initialize ynab-py

To begin using ynab-py, initialize it with your YNAB Bearer token:

from ynab_py import YnabPy
ynab = YnabPy(bearer="YOUR_BEARER_TOKEN_HERE")

Retrieve Budgets

Fetch a dictionary of your budgets:

budgets = ynab.budgets

Retrieve a Budget by Name*

Retrieve a specific budget by its name:

test_budget = ynab.budgets.by(field="name", value="test_budget", first=True)

Retrieve Accounts for a Budget

Fetch all accounts associated with a budget:

test_accounts = test_budget.accounts

Retrieve an Account by Name*

Fetch a specific account within a budget by its name:

test_account = test_budget.accounts.by(field="name", value="test_account", first=True)

Retrieve Transactions for an Account

Fetch all transactions associated with a specific account:

transactions = test_account.transactions

* Note: Multiple items may be returned. You should verify whether the result is a dictionary or a single Budget, Account, or Transaction instance.

from ynab_py.schemas import Account
test_account = test_budget.accounts.by(field="name", value="test_account", first=False)
if isinstance(test_account, Account):
    # Single account returned
else:
    # Multiple accounts returned {account_id: account}

Contributing

We welcome contributions! Here's how to get started:

  1. Fork the Repository: Create a personal copy of the repository on your GitHub account.
  2. Clone the Repository: Clone the forked repository to your local machine:
    git clone https://github.com/<your-username>/<repository-name>.git
    
  3. Create a Branch: Always create a new branch for your changes to keep the history clean:
    git checkout -b <branch-name>
    
  4. Make Your Changes: Edit the code using your preferred editor or IDE.
  5. Commit Your Changes: Provide a clear commit message describing your changes:
    git commit -m "<commit-message>"
    
  6. Push Your Changes: Push the changes to your forked repository:
    git push origin <branch-name>
    
  7. Submit a Pull Request: On GitHub, open a pull request from your fork to the main repository for review.

Please ensure that your contributions do not break the live API tests. Run all tests before submitting your pull request.

Testing

Live API Testing

YNAB's API primarily offers read-only access, so you'll need to create a test budget manually for live API testing.

Live API tests confirm that ynab-py's API calls are correctly interpreted by the server, and that ynab-py can process the server's responses.

Importing a Test Budget

To import a test budget, upload testing/test_budget.ynab4.zip to YNAB by creating a new budget and using the "Migrate a YNAB 4 Budget" option.

Manually Creating a Test Budget

Follow these steps to manually create a test budget:

Item Field Value Notes
Budget name Test Budget Delete all Category Groups and Categories
Category Group name Test Category Group
Category name Test Category
Account name Test Account
Transaction payee Test Payee Belongs to Test Account
memo Test Transaction
category Test Category
Transaction date any future date Belongs to Test Account
date > repeat any frequency
memo Test Scheduled Transaction

Running Tests with Tox

Before running tests, create a testing/.env file with your API Bearer Token using the following format:

# ynab personal access token
API_KEY=your_API_token_goes_here

To run tests:

python -m venv .venv-test
source .venv-test/bin/activate
pip install -r testing/requirements.txt
tox

Documentation

Please ensure any code changes are accompanied by corresponding updates to the documentation. You can generate updated documentation using Handsdown:

python -m venv .venv-docs
source .venv-docs/bin/activate
pip install -r docs/requirements.txt
handsdown

Future Development

  • Implement mock testing.
  • Additional testing for:
    • Server knowledge validation.
    • All non-GET endpoints.
  • Add comprehensive type definitions.

License

ynab-py is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for ynab-py 1.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-py 1.0.0
File Size Uploaded
ynab_py-1.0.0.tar.gz 26.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ynab-py 1.0.0
File Interpreter ABI Platform
ynab_py-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 51.0 kB

Release files / ynab_py-1.0.0.tar.gz

Download URL ynab_py-1.0.0.tar.gz
Size 26.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2ec9a08be9f784b9a9daaa42df81dcc8f7efa7feb52d5b83c53ab0cdcb187aaf
BLAKE2b-256 checksum
How to use checksums
b439071459116b0e8f3e71cee3dcf52d48115ad8b4af3165a74d86c0a9256189
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.1

Release files / ynab_py-1.0.0-py3-none-any.whl

Download URL ynab_py-1.0.0-py3-none-any.whl
Size 24.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea20df07141fbdd4a04613e0632da326904f2679c4fc74cfa006bc81c4b0e3f2
BLAKE2b-256 checksum
How to use checksums
0404d81df22ebbdaa13688967975166ee801dae935dc7c476fe9d95f5cfd29e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.1

Release history Release notifications | RSS feed

This release

1.0.0 This release

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