Skip to content

Kuda

AsyncKuda

Bases: BaseAsyncAPIWrapper

An asynchronous API wrapper to Kuda REST API endpoints.

Parameters:

Name Type Description Default
email str

The email address of your Kuda account with access to an apiKey

required
api_key str

Your Kuda apiKey

required
mode Mode

The mode you desire to use the wrapper in (development or production)

Mode.DEVELOPMENT
Source code in pykuda2/kuda.py
class AsyncKuda(BaseAsyncAPIWrapper):
    """An asynchronous API wrapper to Kuda REST API endpoints.

    Args:
        email: The email address of your Kuda account with access to an apiKey
        api_key: Your Kuda apiKey
        mode: The mode you desire to use the wrapper in (development or production)
    """

    def __init__(self, email: str, api_key: str, mode: Mode = Mode.DEVELOPMENT):
        super().__init__(email=email, api_key=api_key, mode=mode)
        self.accounts = Account(email=email, api_key=api_key, mode=mode)
        self.transactions = Transaction(email=email, api_key=api_key, mode=mode)
        self.billing_and_betting = BillingAndBetting(
            email=email, api_key=api_key, mode=mode
        )
        self.gift_cards = GiftCard(email=email, api_key=api_key, mode=mode)
        self.savings = Savings(email=email, api_key=api_key, mode=mode)
        self.cards = Card(email=email, api_key=api_key, mode=mode)

Kuda

Bases: BaseAPIWrapper

A synchronous API wrapper to Kuda REST API endpoints.

Parameters:

Name Type Description Default
email str

The email address of your Kuda account with access to an apiKey

required
api_key str

Your Kuda apiKey

required
mode Mode

The mode you desire to use the wrapper in (development or production)

Mode.DEVELOPMENT
Source code in pykuda2/kuda.py
class Kuda(BaseAPIWrapper):
    """A synchronous API wrapper to Kuda REST API endpoints.

    Args:
        email: The email address of your Kuda account with access to an apiKey
        api_key: Your Kuda apiKey
        mode: The mode you desire to use the wrapper in (development or production)
    """

    def __init__(self, email: str, api_key: str, mode: Mode = Mode.DEVELOPMENT):
        super().__init__(email=email, api_key=api_key, mode=mode)
        self.accounts = Account(email=email, api_key=api_key, mode=mode)
        self.transactions = Transaction(email=email, api_key=api_key, mode=mode)
        self.billing_and_betting = BillingAndBetting(
            email=email, api_key=api_key, mode=mode
        )
        self.gift_cards = GiftCard(email=email, api_key=api_key, mode=mode)
        self.savings = Savings(email=email, api_key=api_key, mode=mode)
        self.cards = Card(email=email, api_key=api_key, mode=mode)
        # All the attributes above are API wrappers in themselves which means
        # they'll individually try to get the access token with the `emai` and
        # `api_key`. This is like to result in some performance issues. this is
        # a hacky solution to this issue. We use this `Kuda` wrapper to get the
        # `access_token` and feed it to all these attributes, so they don't have
        # to make a request to get the access token.
        self.accounts._saved_token = self._token
        self.transactions._saved_token = self._token
        self.billing_and_betting._saved_token = self._token
        self.gift_cards._saved_token = self._token
        self.savings._saved_token = self._token
        self.cards._saved_token = self._token

Attributes on the Kuda and AsyncKuda classes

The wrapper classes Kuda and AsyncKuda classes have methods bounded to them that provides methods that lets you interact with Kuda. Here's a comprehensive list of those attributes.

Attribute Description Example
accounts Provides methods that let's you interact with Kuda's Account API kuda.accounts.get_admin_account_balance()
transactions Provides methods that let's you interact with Kuda's Account Transactions API kuda.transactions.get_banks()
billing_and_betting Provided methods that let's you interact with Kuda's Bill Payments & Betting Services kuda.billing_and_betting.get_purchased_bills()
gift_cards Provides methods that let's you interact with Kuda's Gift Cards API kuda.gift_cards.get_gift_cards()
savings Provides methods that let's you interact with Kuda's Savings API kuda.savings.get_fixed_savings_account(tracking_reference="12343443435")
cards Provides methods that let's you interact with Kuda's Cards API kuda.cards.get_cards(tracking_reference="24232244")
Using a class attribute on the Kuda class to interact with Kuda
import os
from pykuda2 import Kuda

KUDA_EMAIL_ADDRESS = os.getenv("KUDA_EMAIL_ADDRESS")
KUDA_API_KEY = os.getenv("KUDA_API_KEY")

# You instantiate the wrapper classes
kuda = Kuda(email=KUDA_EMAIL_ADDRESS, api_key=KUDA_API_KEY)

# calling a method by accessing the attributes on `kuda`
response = kuda.accounts.get_admin_account_balance()
print(response)
What the async equivalent might look like
import asyncio
import os
from pykuda2 import AsyncKuda

KUDA_EMAIL_ADDRESS = os.getenv("KUDA_EMAIL_ADDRESS")
KUDA_API_KEY = os.getenv("KUDA_API_KEY")

# You instantiate the wrapper classes
async_kuda = AsyncKuda(email=KUDA_EMAIL_ADDRESS, api_key=KUDA_API_KEY)

# The bounded attributes have the same name for the async equivalent of the `Kuda` wrapper
async def print_admin_balance():
    print(await async_kuda.accounts.get_admin_account_balance())

coroutines = asyncio.gather(print_admin_balance())
loop = asyncio.get_event_loop()
loop.run_until_complete(coroutines)