Skip to main content

A python package that simplifies using the Kuda Bank Api

Project description

PyKuda

A python package that simplifies using the Kuda Bank Api. While the Kuda Bank Api is quite easy to use, this python package makes it seamless and easy to enjoy the Kuda beautiful Open Api. PyKuda uses Kuda's Api v2 which uses an API key and Token for authentication.

Getting started

Install PyKuda

To use this package, install it using the package manager pip:

pip install pykuda

PyKuda has some dependencies which will be installed (requests and python-dotenv). requests is used by PyKuda to make http requests to Kuda's endpoints, while the python-dotenv is responsible for getting the environmental variables which has to be set for the requests to be authenticated; more to be discussed below.

Create Environmental variables

After installation, the next thing is to create .env file where the environmental variables will be stored. Five variables are to be set in the .env file, and they are shown in an example below.

KUDA_KEY="Your Kuda Api Key"
TOKEN_URL="https://kuda-openapi.kuda.com/v2.1/Account/GetToken" # Kuda API v2.1 GetToken URL
REQUEST_URL="https://kuda-openapi.kuda.com/v2.1/" # Kuda API v2.1 Request URL
EMAIL="Your email used to register for the Kuda account"
MAIN_ACCOUNT_NUMBER="Your main Kuda account number"

NB: Please make sure you do not push your .env file to public repositories as the details here are confidential.

Using PyKuda

from pykuda.pykuda import PyKuda

kuda = PyKuda()
response = kuda.bank_list()

# response contains PyKudaResponse which has the status code and data.

Understanding PyKudaResponse

Every Python request is filtered, and the resulting PyKudaResponse object contains three attributes: status_code, data, and error. It's crucial to consistently check the error attribute to confirm the success of the method.

Users should specifically validate that error is False. Despite Kuda returning a 200 HTTP response code, potential errors in the operation might exist. For example, when creating a virtual account with incorrect data, Kuda might respond with a 200 but set status to False. PyKuda handles this intelligently: if a 200 response is received but the status is False, PyKudaResponse is returned with error set to True. This mechanism aids in determining the success of the request.

Successful request

Using the response above as an example;

>>> response
>>> PyKudaResponse(status_code=200, data=[list_of_banks], error=False)

As seen above, the PyKudaResponse returns the status_code, data and error; the data is an already filtered data of which you can access directly by executing response.data.

Failed request

Incase the request wasn't successful, the PyKudaResponse will be different. The data will be a rRsponse Object which you can check to investigate the cause (Maybe your Token is not correct, or the URL, or something else.). Now, let's say the API Key in the .env file was not a correct one and a request was made, the example below shows the response to expect.

>>> response
>>> PyKudaResponse(status_code=401, data=<Response [401]>, error=True)
>>>
>>> respose.data.text # 'Invalid Credentials'
>>> respose.data.reason # 'Unauthorized'

What else can PyKuda do?

PyKuda can be used to make other requests also, if you would like to learn more about how to use PyKuda to make other requests, please check the source code. Hopefully, I would be able to improve this documentation to show examples of how it can be used to make other requests. A list of request PyKuda can make are listed below.

BANK_LIST, ADMIN_CREATE_VIRTUAL_ACCOUNT, RETRIEVE_VIRTUAL_ACCOUNT_BALANCE, ADMIN_RETRIEVE_MAIN_ACCOUNT_BALANCE, FUND_VIRTUAL_ACCOUNT, WITHDRAW_VIRTUAL_ACCOUNT, NAME_ENQUIRY, SINGLE_FUND_TRANSFER, VIRTUAL_ACCOUNT_FUND_TRANSFER, GET_BILLERS_BY_TYPE, VERIFY_BILL_CUSTOMER, PURCHASE_BILL, ADMIN_RETRIEVE_SINGLE_VIRTUAL_ACCOUNT, ADMIN_UPDATE_VIRTUAL_ACCOUNT, ADMIN_ENABLE_VIRTUAL_ACCOUNT, ADMIN_DISABLE_VIRTUAL_ACCOUNT and ADMIN_VIRTUAL_ACCOUNTS.

Please refer to the Kuda's Documentation to read more about these requests.

Contributions & Issues

  • If you would like to contribute and improve this package or it's documentation, please feel free to fork the repository, make changes and open a pull request.
  • If you encounter any issue or bugs, please open an issue.

Author

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

pykuda-1.0.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

pykuda-1.0.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file pykuda-1.0.0.tar.gz.

File metadata

  • Download URL: pykuda-1.0.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for pykuda-1.0.0.tar.gz
Algorithm Hash digest
SHA256 72c95314201e428a582f495bd3af40a295d0edd8446a8c0765d0ffc08208116f
MD5 48aacb61f31225f30aae4869c390ff4b
BLAKE2b-256 449881eee56099008b4c56f3f7af3a0f3a31c2b7c141de275e3bf655cbec7ff5

See more details on using hashes here.

File details

Details for the file pykuda-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pykuda-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for pykuda-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b7d4f6b07c7e86e888fb53c70ae1b2de27cc9dcbad4a55049713b23fa51a6de
MD5 387cbc38e4a0cd9cdf6f5ec832da9f3b
BLAKE2b-256 a484d2d68bb2c5dfc0d80e5cb8b0503fa58ca690a9c52878360b9a3e00e018b5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page