Skip to main content

A Python client for the You Need A Budget (YNAB) API

Project description

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.

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_py-1.0.0.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

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

ynab_py-1.0.0-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file ynab_py-1.0.0.tar.gz.

File metadata

  • Download URL: ynab_py-1.0.0.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for ynab_py-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2ec9a08be9f784b9a9daaa42df81dcc8f7efa7feb52d5b83c53ab0cdcb187aaf
MD5 eebb9bf4451a52e4e4bfe90d8df84ac3
BLAKE2b-256 b439071459116b0e8f3e71cee3dcf52d48115ad8b4af3165a74d86c0a9256189

See more details on using hashes here.

File details

Details for the file ynab_py-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ynab_py-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for ynab_py-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea20df07141fbdd4a04613e0632da326904f2679c4fc74cfa006bc81c4b0e3f2
MD5 2793a375e0ee39c3308db6ed5550a3a6
BLAKE2b-256 0404d81df22ebbdaa13688967975166ee801dae935dc7c476fe9d95f5cfd29e5

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