Access ubank.com.au with Python
Project description
ubank
Access ubank's API with Python.
Contents
Getting started
Install the ubank package (Python 3.11+ required):
$ pip install ubank
Register a new passkey with ubank:
$ python -m ubank name@domain.com --output passkey.pickle
Enter ubank password:
Enter security code sent to 04xxxxx789: 123456
The above writes a new passkey to passkey.pickle.
You'll be prompted for your ubank username and SMS security code.
[!CAUTION] Your passkey grants access to your bank account. It is your responsibility to keep it safe!
Use your passkey to access ubank's API in a Python script:
from ubank import Client, Passkey
# Load passkey from file.
with open("passkey.pickle", "rb") as f:
passkey = Passkey.load(f)
# Authenticate to ubank with passkey and print account balances.
with Client(passkey) as client:
print("Account balances")
for account in client.get("/app/v1/accounts").json()["linkedBanks"][0]["accounts"]:
print(
f"{account['label']} ({account['type']}): {account['balance']['available']} {account['balance']['currency']}"
)
Resulting in the following output:
Account balances
Spend account (TRANSACTION): 765.48 AUD
Savings account (SAVINGS): 1577.17 AUD
Passkeys increment an internal counter with each authentication attempt.
ubank.Client automatically writes the updated passkey object to the passkey file after successful authentication.
ubank API
ubank.Client is an httpx.Client
with a familiar requests-style interface.
Its base_url is set to https://api.ubank.com.au/, so only the path is required when making API requests.
Here are some API endpoints to try (can you find more?):
with Client(passkey) as client:
print(client.get("/app/v1/accounts").json())
print(client.get("/app/v1/accounts/summary").json())
print(client.get("/app/v1/achievements").json())
print(client.get("/app/v1/campaigns").json())
print(client.get("/app/v1/cards").json())
print(client.get("/app/v1/contacts").json())
print(client.get("/app/v1/customer-details").json())
print(client.get("/app/v1/insights").json())
print(client.get("/app/v1/insights/interest").json())
print(client.get("/app/v1/products").json())
print(client.get("/app/v1/promotions").json())
print(client.get("/app/v1/savings-goals").json())
print(client.get("/app/v1/tfn").json())
ubank.Client is intended to be used as a context manager.
This ensures ubank sessions and HTTP connections are ended properly when leaving the with block.
CLI help
$ python -m ubank --help
usage: ubank.py [-h] [-o FILE] [-n PASSKEY_NAME] [-v] username
Registers new passkey with ubank. You will be asked for your ubank password and secret code interactively.
positional arguments:
username ubank username
options:
-h, --help show this help message and exit
-o FILE, --output FILE
writes plaintext passkey to file (default: write to stdout)
-n PASSKEY_NAME, --passkey-name PASSKEY_NAME
sets passkey name (default: ubank.py)
-v, --verbose displays httpx INFO logs
Testing
Run tests locally:
$ uv run pytest -v
test_ubank_client requires a valid passkey.pickle file for testing ubank
authentication.
Skip this test using the following expression:
$ uv run pytest -v -k 'not test_ubank_client'
A GitHub Actions workflow runs tests across a number of Python versions.
Release
Bump project version with hatch:
$ uvx hatch version minor
Old: 2.0.0
New: 2.1.0
Update uv lockfile:
$ uv lock
Publish to PyPI:
$ read -s PASSWORD
$ poetry publish --build -u __token__ -p "$PASSWORD"
Changelog
2.0.0
- Implement passkey registration and authentication.
- Automate releases.
- Support Python 3.11+.
- Migrate from Poetry to uv.
1.1.0
- Set
x-api-versionto fix #4 (thanks @jakepronger!)
1.0.0
- Drop Playwright requirement.
- Re-implement with simpler and lightweight httpx libary.
- Easier access to full ubank API.
0.1.2
- Automate ubank access using Playwright headless browser.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ubank-2.0.0a1.tar.gz.
File metadata
- Download URL: ubank-2.0.0a1.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.5.31
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28aaf57701509b4a6d3a800fcf30681c7d733247599bb2908925cac35de11650
|
|
| MD5 |
cd5dc9448fd6a5ce0ceba09bf18d214d
|
|
| BLAKE2b-256 |
2a141bab41f525a4d4ad174897960b4d5f4f81633fdc081eb1644e206518ec1c
|
File details
Details for the file ubank-2.0.0a1-py3-none-any.whl.
File metadata
- Download URL: ubank-2.0.0a1-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.5.31
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
888f09ce4b7d3ac47f19f98b5d7b2e7bb0f2c97abc7f9bbaaeb29d4394086d97
|
|
| MD5 |
3a380793bcc1c99e178c39d87f78d8b4
|
|
| BLAKE2b-256 |
e1ab269324f119df4ae99d0e0a04a5df4571f6d76ea6fe15e72576e6a84f90e8
|