Skip to main content

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.cbor
Enter ubank password:
Enter security code sent to 04xxxxx789: 123456

The above writes a new passkey to passkey.cbor. 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.cbor", "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.cbor 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.

How to publish a new release

Bump project version with hatch:

$ uvx hatch version minor
Old: 2.0.0
New: 2.1.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.1.0

Find the tag here and create a new release. Publishing a release triggers this workflow, which builds and publishes the package to PyPI.

Changelog

2.0.0

  • Implement passkey registration and authentication.
  • Automate releases.
  • Support Python 3.11+.
  • 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.0.0rc1.tar.gz (22.0 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.0.0rc1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file ubank-2.0.0rc1.tar.gz.

File metadata

  • Download URL: ubank-2.0.0rc1.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.5.31

File hashes

Hashes for ubank-2.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 9f8ad4b2b92151108bebdafc2d6812b8a77f40bd0c64078a4d47b15f2ff4ac04
MD5 13914f4530969cdc389e1755be9d895b
BLAKE2b-256 995d7813edf756b851b56957fac6d1de7a8a368c9029cb26427da2c2bb36fe93

See more details on using hashes here.

File details

Details for the file ubank-2.0.0rc1-py3-none-any.whl.

File metadata

  • Download URL: ubank-2.0.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.5.31

File hashes

Hashes for ubank-2.0.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 3ba8f458450ddfa5efc3b0c356225c4303bc73ad0aeb8bced601627ebe24aa8d
MD5 041f99a5fc49483e3388fbf21d5b773c
BLAKE2b-256 030e3df8cbd7e0280828b8ed67f66e98bf371f609d3d86c67d5fd10a4b10f0bd

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