Package: async-up-bank-api
Async Up Bank APIThis project is a async fork of jcwillox/up-bank-api. I've attempted to keep most things the same but I have changed a fair bit.If there's any issues please let me know.This is an unofficial python wrapper (client) for the australian bank Up's API.🕶️The Up Website📖Up API DocumentationUp API on GithubInstallation$pipinstallasync-up-bank-apiUsageThe code is fully typed and documented so I'd recommend just having a look at the code, or letting syntax completion take the wheel.To use this library you will need a personal access token which can be retrieved fromhttps://developer.up.com.au. When using this library you can either provide the token directly or use the environment variableUP_TOKEN.fromupbankapiimportClient,NotAuthorizedExceptionimportasyncio# use the environment variable UP_TOKENclient=Client()# or directly provide tokenclient=Client(token="MY_TOKEN")# optionally check the token is validasyncdefmain():try:user_id=awaitclient.ping()print("Authorized: "+user_id)exceptNotAuthorizedException:print("The token is invalid")if__name__=='__main__':asyncio.get_event_loop().run_until_complete(main())ExamplesAccountsTransactionsPaginationWebhooksAccountsasyncdefmain():account:Accounttransaction:Transaction# list accountsasyncforaccountinawaitclient.accounts():print(account)# list transactions for accountasyncfortransactioninawaitaccount.transactions():print(transaction)if__name__=='__main__':asyncio.get_event_loop().run_until_complete(main())>>><Account'Up Account'(TRANSACTIONAL):1234.56AUD>>>><TransactionSETTLED:-1.0AUD[7-Eleven]>>>><Account'💰 Savings'(SAVER):12345.67AUD>>>><TransactionSETTLED:10.0AUD[Interest]># get the unique id of an accountaccounts[1].id>>>"d7cd1152-e78a-4ad7-8202-d27cddb02a28"# get a specific account by its unique idsavings=client.account("d7cd1152-e78a-4ad7-8202-d27cddb02a28")savings>>><Account'💰 Savings'(SAVER):12345.67AUD>savings.balance>>>12345.67TransactionsGet transactions across all accounts.>>>list(awaitclient.transactions())[<TransactionSETTLED:-1.0AUD[7-Eleven]>,<TransactionSETTLED:10.0AUD[Interest]>]Get last 5 transactions for a given account id.SAVINGS_ID="d7cd1152-e78a-4ad7-8202-d27cddb02a28"list(awaitclient.account(SAVINGS_ID).transactions(limit=5))>>>[<TransactionSETTLED:10.0AUD[Interest]>]list(awaitclient.transactions(account_id=SAVINGS_ID,limit=5))>>>[<TransactionSETTLED:10.0AUD[Interest]>]Get a specific transaction.awaitclient.transaction("17c577f2-ae8e-4622-90a7-87d95094c2a9")>>><TransactionSETTLED:-1.0AUD[7-Eleven]>PaginationUp's API uses pagination, this means methods in this library that return more than one record with pagination sported will return a instance inheriting fromPagination. This is effectively just an async iterator.Everypage_sizerecords the instance ofPaginationwill make a request for the nextpage_sizerecords asynchronous.Alimitcan be used to limit the maximum number of records returned, when a limit is specified the iterator will never return more thanlimitbut can return less.
Usinglimit=Nonewill return all records.transactions=awaitclient.transactions(limit=5)asyncfortransactionintransactions:print(transactions)print(list(transactions))>>>[<TransactionSETTLED:-1.0AUD[7-Eleven]>,<TransactionSETTLED:10.0AUD[Interest]>]Paginationsupportsslicing, it still returns an iterator and will fetch the records as required.transactions=awaitclient.transactions(limit=20)list(transactions[10:20])>>>[<Transaction...>,...]Note that while it may appear the slice[:limit]has the same effect as specifying alimit, it does not, when you specify a limit the code optimises the page size.
For example, using the slice[:5]will fetch the first 20 records and return only 5, usinglimit=5it will fetch and return the first 5 records. However, if you manually specifypage_size=5then both options have the same effect.WebhooksList users webhookslist(awaitclient.webhooks())>>>[<Webhook'1c3a4fd4-6c57-4aa8-8481-cf31a46bc001':https://mywebhook.tld/c2f89ed40e26c936(HelloWorld!)>]Get a specific webhookawaitclient.webhook("1c3a4fd4-6c57-4aa8-8481-cf31a46bc001")# or equivalentlyawaitclient.webhook.get("1c3a4fd4-6c57-4aa8-8481-cf31a46bc001")>>><Webhook'1c3a4fd4-6c57-4aa8-8481-cf31a46bc001':https://mywebhook.tld/c2f89ed40e26c936(HelloWorld!)>Create a webhookawaitclient.webhook.create("https://mywebhook.tld/c2f89ed40e26c936",description="Hello World!")>>><Webhook'1c3a4fd4-6c57-4aa8-8481-cf31a46bc001':https://mywebhook.tld/c2f89ed40e26c936(HelloWorld!)>Interacting with a webhookwebhook=awaitclient.webhook("1c3a4fd4-6c57-4aa8-8481-cf31a46bc001")# ping the webhookawaitwebhook.ping()>>><WebhookEventPING:webhook_id='1c3a4fd4-6c57-4aa8-8481-cf31a46bc001'># get the webhooks logslist(awaitwebhook.logs())>>>[<WebhookLogBAD_RESPONSE_CODE:response_code=404>]# get the event associated with a log entryawaitwebhook.logs()[0].event>>><WebhookEventPING:webhook_id='1c3a4fd4-6c57-4aa8-8481-cf31a46bc001'># delete the webhookawaitwebhook.delete()When interacting with with a specific webhook there are two options.For example the two code blocks below have the same result (deleting the webhook), however, the first option uses 2 requests and the second option uses only 1 request.
This is because option 1 will request the webhook details, and then send the delete request. Option 2 directly sends the delete request.# Option 1awaitclient.webhook("1c3a4fd4-6c57-4aa8-8481-cf31a46bc001").delete()# Option 2awaitclient.webhook.delete("1c3a4fd4-6c57-4aa8-8481-cf31a46bc001")Each option can be useful depending on the use case. Option 2 is primarily useful when do not already have the Webhook object but have the id and only want to perform a single action.