Python
Learn how to use Okra's new Python SDK to build any fintech idea you have.
Overview
The Okra Python SDK is a Python SDK built upon Okra's open finance API, which is the operating system for financial services. An all-in-one suite for your fintech needs.
Requirements
- Python 3
- Pycharm IDE or any preferred suitable code editor with Python 3 support
- Check out our get started guide to create your developer account and retrieve your Client Token, API Keys, and Private Keys.
- Create a sandbox customer, so you can get connecting immediately.
Installation
- To install with pip -
$ pip install okra_py_official
- To install from the source, clone this repo -
$ git clone <https://github.com/okraHQ/okra_py.git>
- Change directory into the okra_py folder -
$ cd okra_py/
- Install the module -
$ python setup.py install
Getting started
# Import the Okra Auth class
from okra_py.auth import OkraAuth
# INITIALIZATION
# Initialize with a token from okra
ok_mod = OkraAuth(my_okra_token)
# FETCH AUTH
resp = ok_mod.retrieve_auth()
print(resp.status_code, resp.json())
# GET AUTH BY ID
_id = "5rggfdfghjkl4567"
resp_by_id = ok_mod.get_by_id(_id)
print(resp_by_id.status_code, resp_by_id.json())
# GET AUTH BY CUSTOMER
customer_id = "5rggfdfghjkl4567"
resp_by_cus_id = ok_mod.get_by_customer(customer_id=customer_id, page=1, limit=20)
print(resp_by_cus_id.status_code, resp_by_cus_id.json())
# GET AUTH BY DATE
resp_by_date = ok_mod.get_by_date(from_="2020-01-01", to_="2020-04-01" page=1, limit=20)
print(resp_by_date.status_code, resp_by_date.json())
# GET AUTH BY BANK
resp_by_bank_id = ok_mod.get_by_customer(bank_id=bank_id, page=1, limit=20)
print(resp_by_bank_id.status_code, resp_by_bank_id.json())
# GET AUTH BY CUSTOMER & DATE RANGE
customer_id_ = "5rggfdfghjkl4567"
resp_by_date_n_cus = ok_mod.get_by_customer_date(customer_id=customer_id_, from_="2020-01-01",
to_="2020-04-01" page=1, limit=20)
print(resp_by_date_n_cus.status_code, resp_by_date_n_cus.json())
# Import the Okra Balance class
from okra_py.balance import OkraBalance
# INITIALIZATION
# Initialize with a token from okra
okra_balance = OkraBalance(my_okra_token)
# FETCH BALANCES
balances = okra_balance.retrieve_balance()
print(balances.status_code, balances.json())
# FETCH BALANCE BY ID
_id = "5rggfdfghjkl4567"
balances = okra_balance.get_by_id(idx=_id, periodic=True)
"""
When the function includes periodic with a false
value, the periodic field will NOT be included in the response.
When the function does NOT include periodic,
then by default the periodic filed will be included
(the default behavior is periodic is true)
"""
print(balances.status_code, balances.json())
# FETCH BALANCE BY OPTIONS
# Eg of options could be a dictionary of firstName and lastName
options_ = {"first_name": first_name, "last_name": last_name}
balances = okra_balance.get_by_options(options_object=options_)
print(balances.status_code, balances.json())
# FETCH BALANCE BY CUSTOMER
customer_id = "5rggfdfghjkl4567"
resp_by_cus_id = okra_balance.get_by_customer(customer_id=customer_id, periodic=True, page=1,
limit=20)
"""
When the function includes periodic with a false
value, the periodic field will NOT be included in the response.
When the function does NOT include periodic,
then by default, the periodic filed will be included
(the default behavior is periodic is true)
"""
print(resp_by_cus_id.status_code, resp_by_cus_id.json())
# FETCH BALANCE BY ACCOUNT
account_id_ = "5rggfdfghjkl4567"
resp_by_acc_id = okra_balance.get_by_account(account_id=account_id_, periodic=True, page=1,
limit=20)
"""
When the function includes periodic with a false
value, the periodic field will NOT be included in the response.
When the function does NOT include periodic,
then by default, the periodic filed will be included
(the default behavior is periodic is true)
"""
print(resp_by_acc_id.status_code, resp_by_acc_id.json())
# FETCH BALANCE BY TYPE
resp_by_type = okra_balance.get_by_type(type_="ledger_balance", amount=400, periodic=True, page=1,
limit=20)
"""
Args : type_ (string) eg ledger_balance, available_balance
amount (double) eg 4000
"""
print(resp_by_type.status_code, resp_by_type.json())
# FETCH BALANCES BY DATE
resp_by_date = okra_balance.get_by_date(from_="2020-01-01", to_="2020-04-01" page=1, limit=20)
"""
fetch balance info of a customer using date range only
Args : "to_" (string): "2020-04-02",
"from_" (string): "2020-01-01"
"""
print(resp_by_date.status_code, resp_by_date.json())
# FETCH BALANCES BY CUSTOMER & DATE RANGE
customer_id_ = "5rggfdfghjkl4567"
resp_by_date_n_cus = okra_balance.get_by_date(customer_id=customer_id_, from_="2020-01-01",
to_="2020-04-01" page=1, limit=20)
"""
fetch balance info of a customer using date range and customer id
Args : "customer" (string):"5rggfdfghjkl4567",
"to_" (string): "2020-04-02",
"from_" (string): "2020-01-01"
"""
print(resp_by_date_n_cus.status_code, resp_by_date_n_cus.json())
# FETCH REFRESH BALANCE
account_id_ = "5rggfdfghjkl4567"
resp_refresh = okra_balance.get_refresh_balance(account_id=account_id_)
"""
fetch the bank account balance associated with a record's current, savings, and domiciliary
accounts when a slight change occurs in the account.
Args : "account_id" (string),
"""
print(resp_refresh.status_code, resp_refresh.json())
# FETCH ENHANCED BALANCES
customer_id_ = "5rggfdfghjkl4567"
account_id_ = "Afdfghjkl4567D"
resp_enhanced_balance = okra_balance.get_enhanced_balance(account_id=account_id_,
customer_id=customer_id_, from_="2020-01-01", to_="2020-04-01" page=1, limit=20)
"""
fetch a comprehensive paginated list of a specific balance of a customer.
Args : "account_id" (string),
"customer_id" (string),
"to_" (string): "2020-04-02",
"from_" (string): "2020-01-01",
"""
print(resp_enhanced_balance.status_code, resp_enhanced_balance.json())
# Import the Okra Bank class
from okra_py.bank import OkraBank
# INITIALIZATION
# Initialize with a token from okra
okra_bank = OkraBank(my_okra_token)
# FETCH OKRA SUPPORTED BANKS
resp = okra_bank.get_bank_list()
print(resp.status_code, resp.json())
# Import the Okra Identity class
from okra_py.identity import OkraIdentity
# INITIALIZATION
# Initialize with a token from okra
okra_identity = OkraIdentity(my_okra_token)
# FETCH IDENTITIES
resp = okra_identity.get_identity()
print(resp.status_code, resp.json())
# GET IDENTITY BY ID
_id = "5rggfdfghjkl4567"
resp_by_id = okra_identity.get_by_id(idx=_id)
print(resp_by_id.status_code, resp_by_id.json())
# GET IDENTITY BY DATE
resp_by_date = okra_identity.get_by_date(from_="2020-01-01", to_="2020-04-01")
print(resp_by_date.status_code, resp_by_date.json())
# GET IDENTITY BY CUSTOMER
customer_id_ = "5rggfdfghjkl4567"
resp_by_cus_id = okra_identity.get_by_customer(customer_id=customer_id_)
print(resp_by_cus_id.status_code, resp_by_cus_id.json())
# GET IDENTITY BY CUSTOMER & DATE RANGE
customer_id_ = "5rggfdfghjkl4567"
resp_by_cus_id = okra_identity.get_by_customer(customer_id=customer_id_, from_="2020-01-01",
to_="2020-04-01")
print(resp_by_cus_id.status_code, resp_by_cus_id.json())
# VERIFY BVN
bvn_ = "00000000000"
"""
BVN means Bank Verification Number. It is a unique identity given to users that can be verified
across the Nigerian Banking Industry.
lookup BVN and get detailed information on the BVN Identity.
Args : "bvn" (string):"00000000000",
"""
bvn_verification_resp = okra_identity.verify_bvn(bvn=bvn_)
print(bvn_verification_resp.status_code, bvn_verification_resp.json())
# VERIFY COMPANY RC NUMBER
rc_number_ = "00000000000"
company_name_ = "Test Company"
"""
retrieve the full details of a registered company in Nigeria
NOTE - This method is only available for Nigerians..
Args : "company_name" (string):"Test Company",
"rc_number" (string):"0000000000",
"""
rc_verification_resp = okra_identity.verify_company_rc_number(company_name=company_name_,
rc_number=rc_number_)
print(rc_verification_resp.status_code, rc_verification_resp.json())
# VERIFY COMPANY TAX
rc_number_ = "00000000000"
company_name_ = "Test Company"
tin_number_ = "00000000000"
"""
retrieve the full details of registered company in Nigeria and their tax information
NOTE - This method is only available for Nigerians..
Args : "company_name" (string):"Test Company",
"rc_number" (string):"0000000000",
"tin_number" (string):"0000000000",
"""
tax_verification_resp = okra_identity.verify_company_rc_number(company_name=company_name_,
rc_number=rc_number_, tin_number=tin_number_)
print(tax_verification_resp.status_code, tax_verification_resp.json())
# VERIFY COMPANY TIN NUMBER
tin_number_ = "00000000000"
company_name_ = "Test Company"
"""
TIN means Tax Identification Number. It is an identification number used for tax purposes
fetch your end user's details using the Tax Identification Number of the person
NOTE - This method is only available for Nigerians..
Args : "company_name" (string):"Test Company",
"tin_number" (string):"0000000000",
"""
tin_verification_resp = okra_identity.verify_company_rc_number(company_name=company_name_,
tin_number=tin_number_)
print(tin_verification_resp.status_code, tin_verification_resp.json())
# VERIFY NIN
nin_ = "00000000000"
"""
NIN means National Identification Number. It is a means of identification that contains robust
information of an individual.
fetch and verify customers details using National Identification Number.
Args : "nin" (string):"5rggfdfghjkl4567",
"""
nin_verification_resp = okra_identity.verify_customer_nin(nin=nin_)
print(nin_verification_resp.status_code, nin_verification_resp.json())
# MERGE IDENDITIES
initial_ = "String"
final_ = "String"
"""
merge identities in your Okra account
Args : "initial" (string):"5rggfdfghjkl4567",
"final" (string):"5rggfdfghjkl4567",
"""
identity_merge_resp = okra_identity.merge_identities(initial=initial_, final=final_)
print(nin_verification_resp.status_code, identity_merge_resp.json())
# Import the Okra Transaction class
from okra_py.transaction import OkraTransaction
# INITIALIZATION
# Initialize with a token from okra
okra_trx = OkraTransaction(my_okra_token)
# FETCH TRANSACTIONS
resp = okra_trx.get_transactions()
print(resp.status_code, resp.json())
# FETCH TRANSACTIONS BY ID
_id = "5rggfdfghjkl4567"
resp_by_id = okra_trx.get_by_id(_id)
print(resp_by_id.status_code, resp_by_id.json())
# FETCH TRANSACTIONS BY OPTIONS
# Eg of options could be a dictionary of firstName and lastName
options_ = {"first_name": first_name, "last_name": last_name}
trx = okra_trx.get_by_options(options_object=options_)
print(trx.status_code, trx.json())
# FETCH TRANSACTIONS BY CUSTOMER
customer_id = "5rggfdfghjkl4567"
resp_by_cus_id = okra_trx.get_by_customer(customer_id=customer_id, page=1,
limit=20)
# FETCH TRANSACTIONS BY ACCOUNT
account_id_ = "5rggfdfghjkl4567"
resp_by_acc_id = okra_trx.get_by_account(account_id=account_id_, page=1, limit=20)
"""
fetch transaction info using the account id.
Args : "account_id" (string)
"""
print(resp_by_acc_id.status_code, resp_by_acc_id.json())
# FETCH TRANSACTIONS BY BANK
resp_by_bank_id = okra_trx.get_by_customer(bank_id=bank_id, page=1, limit=20)
"""
fetch transaction info using the bank id.
Args : "bank_id" (string)
"""
print(resp_by_bank_id.status_code, resp_by_bank_id.json())
# FETCH TRANSACTIONS BY TYPE
resp_by_type = okra_trx.get_by_type(type_=type, amount=2000, page=1, limit=20)
"""
fetch transaction info using type of balance.
Args : type_ (string) eg ledger_balance, available_balance
amount (string) eg 4000
"""
print(resp_by_type.status_code, resp_by_type.json())
# FETCH TRANSACTIONS BY SPENDING PATTERN
resp_by_sp = okra_trx.get_by_spending_pattern(customer_id=customer_id_, interval=interval_,
channel=channel_, start_date=start_date_, end_date=end_date_)
"""
fetch spending pattern of a customer.
Args : "customer_id" (string),
"interval" (string): eg weekly,
"channel" (string): Specify the channel, eg, cash
"start_date" (string): "2020-01-01"
"end_date" (string): "2020-01-01"
"""
print(resp_by_sp.status_code, resp_by_sp.json())
# FETCH TRANSACTIONS BY CUSTOMER & DATE RANGE
customer_id_ = "5rggfdfghjkl4567"
resp_by_cus_date = okra_trx.get_by_customer(customer_id=customer_id_, from_="2020-01-01",
to_="2020-04-01")
print(resp_by_cus_date.status_code, resp_by_cus_date.json())
# FETCH ENHANCED TRANSACTIONS
account_id_ = "5rggfdfghjkl4567"
resp_for_trx_enhanced = okra_trx.get_enhanced_transaction(account_id=account_id_, page=1,
limit=20)
"""
retrieve a comprehensive paginated list of a specific transaction of a customer.
Args : "account_id" (string)
"""
print(resp_for_trx_enhanced.status_code, resp_for_trx_enhanced.json())
# REFRESH TRANSACTIONS
account_id_ = "5rggfdfghjkl4567"
resp_for_trx_enhanced = okra_trx.refresh_transaction(account_id=account_id_)
"""
retrieve bank account transaction associated with a record's current,
savings, and domiciliary accounts when a slight change occurs in the account.
Args : "account_id" (string)
"""
print(resp_for_trx_enhanced.status_code, resp_for_trx_enhanced.json())
# FETCH TRANSACTIONS BY NUBAN
nuban_ = "5rggfdfghjkl4567"
resp_by_nuban = okra_trx.get_transaction_by_nuban(nuban=nuban_, page=1,
limit=20)
"""
retrieve a paginated list of a specific transaction of a customer by passing the nuban account of
that customer.
Args : "nuban" (string)
"""
print(resp_by_nuban.status_code, resp_by_nuban.json())
# FETCH TRANSACTIONS NETWORK
account_id_ = "5rggfdfghjkl4567"
customer_id_ = "fdfghjkl4567"
resp_by_trx_ntwk =
okra_trx.get_transaction_network(account_id=account_id_,customer_id=customer_id_)
"""
Understand the network of people your users transact with.
Args : "account_id" (string),
"customer_id" (string)
"""
print(resp_by_trx_ntwk.status_code, resp_by_trx_ntwk.json())
# VIEW GUARANTORS
customer_id_ = "fdfghjkl4567"
resp_by_trx_ntwk =
okra_trx.view_guarantors( customer_id=customer_id_, guarantors: [])
"""
grants you access to the guarantors’ Identity KYC profiles of your users, and the ability to
collect payments on their accounts in the event that the main applicant defaults.
Args : "customer_id" (string),
"guarantors": [
{
"name": "GAVIN BELSON",
"email": "[email protected]"
}
]
"""
print(resp_by_trx_ntwk.status_code, resp_by_trx_ntwk.json())
# DOWNLOAD TRANSACTIONS BY RECORD ID
record_id_ = "fdfghjkl4567"
download_trx =
okra_trx.download_transactions( record_id=record_id_, download_type)
"""
allows you to retrieve up to 24 months of a transaction history of a user in CSV format.
Args : "record_id" (string),
"download_type" (string): You can specify the download type, currently we support csv.
"""
print(download_trx.status_code, download_trx.json())
# GET COMPLETE VIEW
customer_id_ = "fdfghjkl4567"
resp_by_cmplt_view = okra_trx.get_complete_view(bvn=bvn_, customer_id=customer_id_)
"""
allows you to view other bank accounts of a customer, allowing the ability to prompt them to
connect all owned accounts and provide consent to access data.
Args : "bvn" (string),
"customer_id" (string): Customer's Okra unique id.
"""
print(resp_by_cmplt_view.status_code, resp_by_cmplt_view.json())
# FETCH BENEFACTORS
resp_by_bn = okra_trx.get_benefactors(account_id=account_id_, customer_id=customer_id_,
bank_id=bank_id_)
"""
allows you to create a graph of transactions,
linking each person’s transactions to another benefactor's transactions.
Args : "account_id" (string),
"customer_id" (string): Customer's Okra unique id.
"bank_id" (string): Customer's Okra unique id.
"""
print(resp_by_bn.status_code, resp_by_bn.json())
# DOWNLOAD TRANSACTIONS
download_trx =
okra_trx.download_records(download_type)
"""
allows you to download all the records in your Okra account.
Args : "download_type" (string): You can specify the download type, currently we support csv.
"""
print(download_trx.status_code, download_trx.json())
# FETCH REALTIME BALANCE
resp_by_real_time = okra_trx.get_real_time_balance(account_id=account_id_, record_id=record_id_,
currency=currency_)
"""
fetch the real-time TRANSACTION at anytime on each of a Record's accounts.
Args : "account_id" (string),
"record_id" (string):
"currency" (string):
"""
print(resp_by_real_time.status_code, resp_by_real_time.json())
# Import the Okra Incomes class
from okra_py.income import OkraIncome
# INITIALIZATION
# Initialize with a token from okra
okra_income = OkraIncome(my_okra_token)
# FETCH INCOME RECORDS
resp = okra_income.get_incomes()
print(resp.status_code, resp.json())
# FETCH INCOME RECORD BY ID
_id = "5rggfdfghjkl4567"
resp_by_id = okra_income.get_by_id(_id)
print(resp_by_id.status_code, resp_by_id.json())
# FETCH INCOME RECORD BY CUSTOMER ID
_id = "5rggfdfghjkl4567"
resp_by_cus_id = okra_income.get_by_customer(customer_id=_id)
print(resp_by_cus_id.status_code, resp_by_cus_id.json())
# FETCH INCOME RECORD BY CUSTOMER & DATE RANGE
customer_id_ = "5rggfdfghjkl4567"
resp_by_cus_id = okra_income.get_by_customer_date(customer_id=customer_id_, from_="2020-01-01",
to_="2020-04-01")
print(resp_by_cus_id.status_code, resp_by_cus_id.json())
# FETCH INCOME RECORD BY DATE RANGE
resp_by_cus_id = okra_income.get_by_date(from_="2020-01-01", to_="2020-04-01")
print(resp_by_cus_id.status_code, resp_by_cus_id.json())
# PROCESS INCOME
customer_id_ = "5rggfdfghjkl4567"
resp_by_cus_id = okra_income.process_income(customer_id=customer_id_, bank="bank_id")
"""
process the income of particular customer using the customer's id.
Args : "customer_id" (string)
"bank" (string)
"""
print(resp_by_cus_id.status_code, resp_by_cus_id.json())
# VERIFY REVENUE
customer_id_ = "5rggfdfghjkl4567"
resp = okra_income.verify_revenue(customer_id=customer_id_, pdf=TRUE,
from_="2020-01-01", to_="2020-04-02")
"""
verify in real-time the revenue of any corporate entity.
Args : "customer" (string):"5rggfdfghjkl4567",
"pdf" (boolean): False,
"to_" (string): "2020-04-02",
"from_" (string): "2020-01-01"
"""
print(resp.status_code, resp.json())
For more options, check out a list of all the available Widget Properties to add to your widget options below.
View a complete list of customizable options here
Okra gives provision to access the response data on the mobile device. Okra wraps the response in the OkraHandler object and passes it back to the View which called it.
OkraHandler
Name | Type | Default Value | Description |
---|---|---|---|
isDone | boolean | false | It indicates if the okra process has finished. |
isSuccessful | boolean | false | It indicates if the okra process was successful. |
hasError | boolean | false | It indicates if the okra process has an error. |
Data | Json | null | This is the response that okra provides. |
Not a developer?
Get started without writing a single line of code, Try our App Builder! Click here to get started
Updated 2 months ago