Coder Social home page Coder Social logo

gchiam / ynab-client-python Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 7.0 137 KB

Unofficial Python Client for YNAB API v1

Home Page: https://api.youneedabudget.com/v1

License: Apache License 2.0

Shell 0.29% Python 99.71%
python ynab ynab-api api-client swagger swagger-codegen python-2 python-3

ynab-client-python's Introduction

YNAB API v1 Python Client

Build Status Coverage Status

This is the Python client for the YNAB API v1.

Please read the YNAB API documentation for an overview of using the API and a complete list of available resources.

This Python package is automatically generated by the Swagger Codegen project:

  • API version: 1.0.0
  • Build package: io.swagger.codegen.languages.PythonClientCodegen

Requirements.

Python 2.7 and 3.4+

Installation & Usage

pip install

If the python package is hosted on Github, you can install directly from Github

pip install ynab-client

(you may need to run pip with root permission: sudo pip install ynab-client)

Then import the package:

import ynab_client

Setuptools

Install via Setuptools.

python setup.py install --user

(or sudo python setup.py install to install the package for all users)

Then import the package:

import ynab_client

Getting Started

Please follow the installation procedure and then run the following:

from __future__ import print_function
import time
import ynab_client
from ynab_client.rest import ApiException
from pprint import pprint

# Configure API key authorization: bearer
configuration = ynab_client.Configuration()
configuration.api_key_prefix['Authorization'] = 'Bearer'
configuration.api_key['Authorization'] = 'YOUR_API_KEY'

# create an instance of the API class
api_instance = ynab_client.BudgetsApi()

try:
    api_response = api_instance.get_budgets()
    pprint(api_response)
except ApiException as e:
    print("Exception when calling BudgetApi->get_budgets: %s\n" % e)

Documentation for API Endpoints

All URIs are relative to https://api.youneedabudget.com/v1

Class Method HTTP request Description
AccountsApi get_account_by_id GET /budgets/{budget_id}/accounts/{account_id} Single account
AccountsApi get_accounts GET /budgets/{budget_id}/accounts Account list
BudgetsApi get_budget_by_id GET /budgets/{budget_id} Single budget
BudgetsApi get_budget_settings_by_id GET /budgets/{budget_id}/settings Budget Settings
BudgetsApi get_budgets GET /budgets List budgets
CategoriesApi get_categories GET /budgets/{budget_id}/categories List categories
CategoriesApi get_category_by_id GET /budgets/{budget_id}/categories/{category_id} Single category
MonthsApi get_budget_month GET /budgets/{budget_id}/months/{month} Single budget month
MonthsApi get_budget_months GET /budgets/{budget_id}/months List budget months
PayeeLocationsApi get_payee_location_by_id GET /budgets/{budget_id}/payee_locations/{payee_location_id} Single payee location
PayeeLocationsApi get_payee_locations GET /budgets/{budget_id}/payee_locations List payee locations
PayeeLocationsApi get_payee_locations_by_payee GET /budgets/{budget_id}/payees/{payee_id}/payee_locations List locations for a payee
PayeesApi get_payee_by_id GET /budgets/{budget_id}/payees/{payee_id} Single payee
PayeesApi get_payees GET /budgets/{budget_id}/payees List payees
ScheduledTransactionsApi get_scheduled_transaction_by_id GET /budgets/{budget_id}/scheduled_transactions/{scheduled_transaction_id} Single scheduled transaction
ScheduledTransactionsApi get_scheduled_transactions GET /budgets/{budget_id}/scheduled_transactions List scheduled transactions
TransactionsApi bulk_create_transactions POST /budgets/{budget_id}/transactions/bulk Bulk create transactions
TransactionsApi create_transaction POST /budgets/{budget_id}/transactions Create new transaction
TransactionsApi get_transactions GET /budgets/{budget_id}/transactions List transactions
TransactionsApi get_transactions_by_account GET /budgets/{budget_id}/accounts/{account_id}/transactions List account transactions
TransactionsApi get_transactions_by_category GET /budgets/{budget_id}/categories/{category_id}/transactions List category transactions
TransactionsApi get_transactions_by_id GET /budgets/{budget_id}/transactions/{transaction_id} Single transaction
TransactionsApi get_transactions_by_payee GET /budgets/{budget_id}/payees/{payee_id}/transactions List payee transactions
TransactionsApi update_transaction PUT /budgets/{budget_id}/transactions/{transaction_id} Updates an existing transaction
UserApi get_user GET /user User info

Documentation For Models

Documentation For Authorization

bearer

  • Type: API key
  • API key parameter name: Authorization
  • Location: HTTP header

ynab-client-python's People

Contributors

apockill avatar gchiam avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

ynab-client-python's Issues

500 Error on `create_transaction`

Hi,
this library is great. Thanks for sharing.

I adapted the create transaction example and am facing a 500 error.

    import ynab_client
    from ynab_client.rest import ApiException
    from ynab_client import SaveTransactionWrapper, SaveTransaction
    conf = config[DOMAIN]

    # Configure API key authorization: bearer
    configuration = ynab_client.Configuration()
    configuration.api_key_prefix['Authorization'] = 'Bearer'
    configuration.api_key['Authorization'] = conf.get(CONF_API_KEY)

    api_instance = ynab_client.TransactionsApi(ynab_client.ApiClient(configuration))
    _LOGGER.info(conf)
    _LOGGER.info(conf.get(CONF_API_KEY))
    _LOGGER.info(conf.get(CONF_BUDGET_ID))
    _LOGGER.info(conf.get(CONF_DEFAULT_ACCOUNT))


        body = await request.json()
        _LOGGER.info(body)

        regex = r"\$(\d*)\.(\d*).*at\s*([\w\s]*[^\s])\s*on\s*([\w\s]*)"

        matches = re.findall(regex, body['message'], re.MULTILINE)
        if True: #len(matches) == 1:
            _LOGGER.info(matches)
            match = matches[0]
            
            dollars = match[0]
            cents = match[1]

            _LOGGER.info(dollars)
            _LOGGER.info(cents)
            payee = match[2]
            _LOGGER.info(payee)

            category = match[3]
            _LOGGER.info(category)
            transaction = SaveTransaction(
                date= dt.as_local(dt.now()), 
                amount=dollars*100+cents,
                cleared='cleared',
                approved=True,
                account_id=conf.get(CONF_DEFAULT_ACCOUNT),

            )


            payload = SaveTransactionWrapper(transaction)
    

            try:
                api_response = api_instance.create_transaction(conf.get(CONF_BUDGET_ID), payload)
                _LOGGER.info(api_response)
                return api_response
            except ApiException as e:
                _LOGGER.info("Exception when calling TransactionsApi->create_transaction: %s\n" % e)
                return e;

Is this a known issue? I created a SaveTransaction object, as you can see and passed that into SaveTransactionWrapper.

This is the corresponding log and error::

2019-02-18 16:38:00 INFO (MainThread) [homeassistant.components.http.view] Serving /api/webhook/ynab to 192.168.0.2 (auth: False)
2019-02-18 16:38:00 INFO (MainThread) [custom_components.ynab_gateway] {'title': 'CommBank', 'message': '$710.49 spent at Aldi on Groceries.', 'time': ''}
2019-02-18 16:38:00 INFO (MainThread) [custom_components.ynab_gateway] [('710', '49', 'Aldi', 'Groceries')]
2019-02-18 16:38:00 INFO (MainThread) [custom_components.ynab_gateway] 710
2019-02-18 16:38:00 INFO (MainThread) [custom_components.ynab_gateway] 49
2019-02-18 16:38:00 INFO (MainThread) [custom_components.ynab_gateway] Aldi
2019-02-18 16:38:00 INFO (MainThread) [custom_components.ynab_gateway] Groceries
2019-02-18 16:38:02 INFO (MainThread) [custom_components.ynab_gateway] Exception when calling TransactionsApi->create_transaction: (500)
Reason: Internal Server Error
HTTP response headers: HTTPHeaderDict({'Server': 'Cowboy', 'Date': 'Mon, 18 Feb 2019 08:38:01 GMT', 'Connection': 'keep-alive', 'Content-Type': 'application/json; charset=utf-8', 'Vary': 'Accept-Encoding, Origin', 'Cache-Control': 'no-cache', 'X-Request-Id': 'eec1a884-ecf2-4176-b910-2a62cbe7617a', 'X-Runtime': '0.062603', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains', 'Transfer-Encoding': 'chunked', 'Via': '1.1 vegur'})
HTTP response body: {"error":{"id":"500","name":"internal_server_error","detail":"An unexpected error has occurred"}}


2019-02-18 16:38:02 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/real_ip.py", line 34, in real_ip_middleware
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/ban.py", line 67, in ban_middleware
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/auth.py", line 99, in auth_middleware
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/view.py", line 141, in handle
    'Got: {}').format(result)
AssertionError: Result should be None, string, bytes or Response. Got: (500)
Reason: Internal Server Error
HTTP response headers: HTTPHeaderDict({'Server': 'Cowboy', 'Date': 'Mon, 18 Feb 2019 08:38:01 GMT', 'Connection': 'keep-alive', 'Content-Type': 'application/json; charset=utf-8', 'Vary': 'Accept-Encoding, Origin', 'Cache-Control': 'no-cache', 'X-Request-Id': 'eec1a884-ecf2-4176-b910-2a62cbe7617a', 'X-Runtime': '0.062603', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains', 'Transfer-Encoding': 'chunked', 'Via': '1.1 vegur'})
HTTP response body: {"error":{"id":"500","name":"internal_server_error","detail":"An unexpected error has occurred"}}


Does not work with Python 3.7

Library does not import on Python 3.7. Simple reproduction:

$ python --version
Python 3.7.4

$ python -c "import ynab_client"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/ralmeida/.pyenv/versions/3.7.4/lib/python3.7/site-packages/ynab_client/__init__.py", line 19, in <module>
    from ynab_client.api.accounts_api import AccountsApi
  File "/Users/ralmeida/.pyenv/versions/3.7.4/lib/python3.7/site-packages/ynab_client/api/__init__.py", line 6, in <module>
    from ynab_client.api.accounts_api import AccountsApi
  File "/Users/ralmeida/.pyenv/versions/3.7.4/lib/python3.7/site-packages/ynab_client/api/accounts_api.py", line 133
    async=params.get('async'),
        ^
SyntaxError: invalid syntax

I tested with 3.7.4, but any 3.7+ version should give the same problem, since async is now a reserved Python keyword. In 3.6.9 it works fine (as it should with other previous versions as well).

Maybe it's a swagger-codegen problem?

Cannot fetch budgets

Hi there,

I've obtained my API key and I'm trying to run the code, implemented in the "Getting Started" section.
After changing YOUR_API_KEY to my own I'm getting:

Traceback (most recent call last): File "budget.py", line 16, in <module> api_response = api_instance.get_budgets() File "/usr/local/lib/python2.7/site-packages/ynab_client/api/budgets_api.py", line 248, in get_budgets (data) = self.get_budgets_with_http_info(**kwargs) # noqa: E501 File "/usr/local/lib/python2.7/site-packages/ynab_client/api/budgets_api.py", line 315, in get_budgets_with_http_info collection_formats=collection_formats) File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 322, in call_api _preload_content, _request_timeout) File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 161, in __call_api return_data = self.deserialize(response_data, response_type) File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 233, in deserialize return self.__deserialize(data, response_type) File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 272, in __deserialize return self.__deserialize_model(data, klass) File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 613, in __deserialize_model kwargs[attr] = self.__deserialize(value, attr_type) File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 272, in __deserialize return self.__deserialize_model(data, klass) File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 613, in __deserialize_model kwargs[attr] = self.__deserialize(value, attr_type) File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 250, in __deserialize for sub_data in data] File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 272, in __deserialize return self.__deserialize_model(data, klass) File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 613, in __deserialize_model kwargs[attr] = self.__deserialize(value, attr_type) File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 272, in __deserialize return self.__deserialize_model(data, klass) File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 613, in __deserialize_model kwargs[attr] = self.__deserialize(value, attr_type) File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 264, in __deserialize return self.__deserialize_primitive(data, klass) File "/usr/local/lib/python2.7/site-packages/ynab_client/api_client.py", line 544, in __deserialize_primitive return six.u(data) File "/usr/local/lib/python2.7/site-packages/six.py", line 653, in u return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape") TypeError: decoding Unicode is not supported
Am I missing something?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.