Usage#
Installation#
To use lunchable, first install it using pip:
Client#
The LunchMoney client is the main entrypoint
for interacting with the Lunch Money API. It defaults to inheriting the LUNCHMONEY_ACCESS_TOKEN
environment variable, but can be created with an explicit access_token
parameter.
Read more about Interacting with Lunch Money to see what else you can do.
Transactions#
Retrieve a list of TransactionObject
#
from typing import List
from lunchable import LunchMoney
from lunchable.models import TransactionObject
lunch = LunchMoney(access_token="xxxxxxx")
transactions: List[TransactionObject] = lunch.get_transactions(
start_date="2020-01-01",
end_date="2020-01-31"
)
Retrieve a single transaction (TransactionObject
)#
from lunchable import LunchMoney
from lunchable.models import TransactionObject
lunch = LunchMoney(access_token="xxxxxxx")
transaction: TransactionObject = lunch.get_transaction(transaction_id=1234)
The above code returns a TransactionObject with ID # 1234 (assuming it exists)
Update a transaction with a TransactionUpdateObject
#
from datetime import datetime
from typing import Any, Dict
from lunchable import LunchMoney
from lunchable.models import TransactionUpdateObject
lunch = LunchMoney(access_token="xxxxxxx")
transaction_note = f"Updated on {datetime.now()}"
notes_update = TransactionUpdateObject(notes=transaction_note)
response: Dict[str, Any] = lunch.update_transaction(
transaction_id=1234,
transaction=notes_update
)
Update a TransactionObject
with itself#
from datetime import datetime, timedelta
from lunchable import LunchMoney
from lunchable.models import TransactionObject
lunch = LunchMoney(access_token="xxxxxxx")
transaction: TransactionObject = lunch.get_transaction(transaction_id=1234)
transaction.notes = f"Updated on {datetime.now()}"
transaction.date = transaction.date + timedelta(days=1)
response = lunch.update_transaction(
transaction_id=transaction.id,
transaction=transaction
)
Create a new transaction with a TransactionInsertObject
#
transactions
can be a single TransactionInsertObject
or a list of TransactionInsertObject
.
from lunchable import LunchMoney
from lunchable.models import TransactionInsertObject
lunch = LunchMoney(access_token="xxxxxxx")
new_transaction = TransactionInsertObject(
payee="Example Restaurant",
amount=120.00,
notes="Saturday Dinner"
)
new_transaction_ids = lunch.insert_transactions(transactions=new_transaction)