Python

Python Library by Xendit is a way for you to integrate Xendit features using your Python application!

Xendit Python library currently supports these products:

  • Credit / Debit Cards (via Payments API)
  • E-Wallets (via Payments API)
  • Virtual Accounts (via Payments API)
  • Retail Outlets (via Payments API)
  • QR Code (via Payments API)
  • Customers
  • Invoices
  • Payouts
  • Balances
  • Transactions

Compatibility

Our Python library is compatible with Python 3.10 or later

Installation

Below are alternatives of installation using pip, use ONE alternative and try the next one if there are issues

  • Install package
pip install xendit-python
  • Install directly from Xendit's Github Repository
pip install git+https://github.com/xendit/xendit-python.git
  • Install directly from Xendit's Github Repository with root permission
sudo pip install git+https://github.com/xendit/xendit-python.git

Then import the package:

import xendit

Check out our Python source on Github for the complete installation guide and to verify the latest version.

Authorization

The SDK needs to be instantiated using your secret API key obtained from the Xendit Dashboard. You can sign up for a free Dashboard account here.

import xendit
from xendit.apis import BalanceApi
from pprint import pprint

xendit.set_api_key('XENDIT_API_KEY')

client = xendit.ApiClient()

try:
    response = BalanceApi(client).get_balance('CASH')
    pprint(response)
except xendit.XenditSdkException as e:
    print("Exception when calling BalanceApi->get_balance: %s\n" % e)

Sample Usage

You can use the APIs below to interface with Xendit's BalanceApi. To start using the API, you need to configure the secret key and initiate the client instance.

import time
import xendit
from xendit.apis import BalanceApi
from xendit.balance_and_transaction.model.server_error import ServerError
from xendit.balance_and_transaction.model.validation_error import ValidationError
from xendit.balance_and_transaction.model.balance import Balance
from pprint import pprint

# See configuration.py for a list of all supported configuration parameters.
xendit.set_api_key('XENDIT API KEY')


# Enter a context with an instance of the API client
api_client = xendit.ApiClient()
# Create an instance of the API class
api_instance = BalanceApi(api_client)
account_type = "CASH" # str | The selected balance type
currency = "IDR" # str | Currency for filter for customers with multi currency accounts
for_user_id = "5dbf20d7c8eb0c0896f811b6" # str | The sub-account user-id that you want to make this transaction for. This header is only used if you have access to xenPlatform. See xenPlatform for more information

# example passing only required values which don't have defaults set
# and optional values
try:
    # Retrieves balances for a business, default to CASH type
    api_response = api_instance.get_balance(account_type=account_type, currency=currency, for_user_id=for_user_id)
    pprint(api_response)
except xendit.XenditSdkException as e:
    print("Exception when calling BalanceApi->get_balance: %s\n" % e)

For sample of other available APIs, please refer to our Python SDK Github Documentation.

Last Updated on 2024-01-09