Skip to main content

Access ubank.com.au with Python

Project description

ubank

Access ubank's API using Python.

Getting started

Install ubank using pip:

pip install ubank

The ubank package provides a script to register a new passkey with ubank:

$ ubank name@domain.com --output passkey.txt
Enter ubank password:
Enter security code sent to 04xxxxx789: 123456

This saves a new passkey to passkey.txt (encrypted with your ubank password). You'll be prompted for your ubank username and SMS security code interactively.

[!CAUTION] Your passkey grants access to your bank account. It is your responsibility to keep it safe!

Create a script named balances.py:

from getpass import getpass

from ubank import Api, Passkey

# Load passkey from file.
with open("passkey.txt", "rb") as f:
    passkey = Passkey.load(f, password=getpass("Enter ubank password: "))

# Print account balances.
with Api(passkey) as api:
    for account in api.get_accounts().linkedBanks[0].accounts:
        print(
            f"{account.label} ({account.type}): {account.balance.available} {account.balance.currency}"
        )

Run the script to print your account balances:

$ python balances.py
Enter ubank password:
Spend account (TRANSACTION): 765.48 AUD
Savings account (SAVINGS): 1577.17 AUD

Contents

ubank CLI

The ubank module provides a CLI for registering a new passkey:

$ ubank --help
usage: ubank [-h] [-o FILE] [-n PASSKEY_NAME] [-v] username

Returns a new passkey registered with ubank.

positional arguments:
  username              ubank username

options:
  -h, --help            show this help message and exit
  -o, --output FILE     writes encrypted passkey to file (default: write to stdout)
  -n, --passkey-name PASSKEY_NAME
                        sets passkey name (default: ubank.py)
  -v, --verbose         displays httpx INFO logs

You will be asked for your ubank password and secret code interactively. The passkey is encrypted with your ubank password.

ubank API

The ubank.Api class provides a number of methods for accessing ubank's API:

from datetime import date
from getpass import getpass

from ubank import Api, Passkey, TransactionsSearchBody

with open("passkey.txt", "rb") as f:
    passkey = Passkey.load(f, password=getpass("Enter ubank password: "))

with Api(passkey) as api:
    api.post_accounts_transactions_search(
        body=TransactionsSearchBody(fromDate=date(2025, 1, 1), toDate=date(2025, 2, 1))
    )
    bank = api.get_accounts().linkedBanks[0]
    api.get_account_transactions(
        account_id=bank.accounts[0].id,
        bank_id=bank.bankId,
        customerId=api.get_customer_details().customerId,
    )
    api.get_cards()
    api.get_devices(deviceUuid=passkey.device_id)
    api.get_contacts()

Example web application

notebook.py is a marimo notebook that looks like this this. It demonstrates usage of the API client class to explore ubank's API.

Open notebook.py in the marimo editor:

uv run marimo edit notebook.py

Run the notebook as a web application:

uv run marimo edit notebook.py

How to set up a development environment

Install uv:

curl -LsSf https://astral.sh/uv/install.sh | sh

Clone this repository:

git clone git@github.com:eidorb/ubank.git
cd ubank

uv ensures Python dependencies compatible with those defined in pyproject.toml are automatically installed:

$ uv run python -c 'import ubank; print(ubank.__version__)'
Using CPython 3.13.2 interpreter at: /opt/homebrew/opt/python@3.13/bin/python3.13
Creating virtual environment at: .venv
Installed 17 packages in 22ms
2.0.0

How to test

Run all tests:

uv run -m pytest -v

How to publish a new release

Bump project version with hatch:

$ uvx hatch version release
Old: 2.0.0rc2
New: 2.0.0

Update test_version test.

Create version tag and push to GitHub:

$ git tag "v$(uvx hatch version)"
$ git push origin "v$(uvx hatch version)"
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:eidorb/ubank.git
 * [new tag]         v2.0.0 -> v2.0.0

Open new release form for tag:

open "https://github.com/eidorb/ubank/releases/new?tag=v$(uvx hatch version)"

Publishing a release triggers this workflow which builds and publishes the package to PyPI.

Changelog

2.1.0

  • Passkey encrypted with ubank password
  • Add API client Api
  • Add marimo notebook

2.0.0

  • Implement passkey registration and authentication (fixes #6).
  • Automate releases.
  • Support Python 3.9+.
  • Migrate from Poetry to uv.

1.1.0

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ubank-2.1.0.tar.gz (853.1 kB view details)

Uploaded Source

Built Distribution

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

ubank-2.1.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file ubank-2.1.0.tar.gz.

File metadata

  • Download URL: ubank-2.1.0.tar.gz
  • Upload date:
  • Size: 853.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.2

File hashes

Hashes for ubank-2.1.0.tar.gz
Algorithm Hash digest
SHA256 4258e442ac523eb43c95a8c13fca0cb6e0d9d58f7b443eeafd62af5e43a90f2d
MD5 be9b7bee597a6517e8e1181d10b8cabb
BLAKE2b-256 2137d501f3c7d8901d34c1491b31c199372a335fdfad20c27c9ba6be12a0d9a0

See more details on using hashes here.

File details

Details for the file ubank-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: ubank-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.2

File hashes

Hashes for ubank-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee6512330c9c658d98a481f60c9caf5ae820e3f9df225085a4ae89458a453c56
MD5 b456a833ac81e53ecd87fc6bf5822464
BLAKE2b-256 d00129c1233cb2d15f6bc8a76d2302dc317d46803e3c906fc9efdbcacd6116c0

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