An unofficial python package that provides access to parts of the Starling bank API. Designed to be used for personal use (i.e. using personal access tokens).
18/12/2019
- Removed
available_to_spend
property as this is no longer supported by the API.
23/02/2018
- Updated to use v2 API.
-
currency
is no longer a property of the balance data. -
id
andname
are no longer properties of the account data. -
account_number
is nowaccount_identifier
. -
sort_code
is nowbank_identifier
. - An API call is now made when initialising a StarlingAccount instance, even with
update=False
. This is to get the minimum data needed to start working with an account.
pip install starlingbank
To use all of the functionality this package affords, the following API scopes are required:
- account:read
- account-identifier:read
- balance:read
- savings-goal:read
- savings-goal-transfer:read
- savings-goal-transfer:create
from starlingbank import StarlingAccount
my_account = StarlingAccount("<INSERT API TOKEN HERE>")
If using a sandbox token:
my_account = StarlingAccount("<INSERT API TOKEN HERE>", sandbox=True)
By default, to save on wasted API calls only minimal data is collected when you initialise a StarlingAccount. To optionally update all data on initialisation use the following:
my_account = StarlingAccount("<INSERT API TOKEN HERE>", update=True)
3 data sets are currently supported:
- Basic Account Data
- Balance Data
- Savings Goal Data
You have to request / refresh each set of data as required with the following commands:
my_account.update_account_data()
my_account.update_balance_data()
my_account.update_savings_goal_data()
Properties:
- account_identifier
- bank_identifier
- currency
- iban
- bic
- created_at
Example:
print(my_account.account_identifier)
Properties:
- cleared_balance
- effective_balance
- pending_transactions
- accepted_overdraft
Example:
print(my_account.effective_balance)
Savings goals are stored as a dictionary of objects where the dictionary key is the savings goals uid. To get a list of savings goal names and their respective uids you can run:
for uid, goal in my_account.savings_goals.items():
print("{0} = {1}".format(uid, goal.name))
Each goal has the following properties:
- uid
- name
- target_currency
- target_minor_units
- total_saved_currency
- total_saved_minor_units
Note: Values are in minor units e.g. £1.50 will be represented as 150.
Example:
print(my_account.savings_goals['c8553fd8-8260-65a6-885a-e0cb45691512'].total_saved_minor_units)
The update_savings_goal_data()
method will update all savings goals but you can also update them individually with the following method:
my_account.savings_goals['c8553fd8-8260-65a6-885a-e0cb45691512'].update()
You can add funds to a savings goal with the followng method:
my_account.savings_goals['c8553fd8-8260-65a6-885a-e0cb45691512'].deposit(1000)
You can add funds to a savings goal with the followng method:
my_account.savings_goals['c8553fd8-8260-65a6-885a-e0cb45691512'].withdraw(1000)
Note: Both methods above will call an update after the transfer so that the local total_saved value is correct.
You can download the image associated with a savings goal to file with the following method:
my_account.savings_goals['c8553fd8-8260-65a6-885a-e0cb45691512'].get_image('<YOUR CHOSEN FILENAME>.png')
Note: If the filename is ommitted the name of the goal will be used. You can optionally specify a full path alongside the filename if required.