Overview
The Bila Python SDK provides convenient access to the Bila REST API from any Python 3.9+ application. It includes type definitions for all request params and response fields, and offers both synchronous and asynchronous clients.Fully Typed
Type definitions for every request param and response field.
Sync & Async
Synchronous and asynchronous clients powered by httpx.
Comprehensive
Access to all Bila API features: Accounts, Transfers, Collections, and more.
Stainless Generated
Consistently structured and always up-to-date with the latest API changes.
Installation
Quick Start
api_key keyword argument, it’s recommended to use python-dotenv to add BILA_API_KEY="My API Key" to your .env file so your API key isn’t stored in source control.
API Classes
The SDK is organized into resources, each handling a specific domain:| Resource | Description |
|---|---|
| Accounts | Retrieve accounts, list accounts, and check balances |
| TransferRecipients | Manage payout recipients for bank and mobile money transfers |
| Transfers | Send payouts via bank transfer and mobile money |
| Collections | Collect payments via mobile money |
| Transactions | Retrieve and list transaction history |
| Webhooks | Configure webhooks and manage delivery history |
| Banks | List supported banks and financial institutions |
| Resolve | Verify bank account and mobile money details |
Accounts
Manage your Bila wallets and check balances. Types:AccountRetrieveResponse, AccountListResponse, AccountGetBalanceResponse
Methods
client.accounts.retrieve(id)
Retrieve details for a specific account.
AccountRetrieveResponse
client.accounts.list(**params)
List all accounts associated with your profile.
AccountListResponse
client.accounts.get_balance(id)
Check the real-time balance of an account.
AccountGetBalanceResponse
TransferRecipients
Manage payout recipients for bank and mobile money transfers. Types:TransferRecipientRetrieveResponse, TransferRecipientListResponse, TransferRecipientCreateBankAccountResponse, TransferRecipientCreateMobileMoneyResponse
Methods
client.transfer_recipients.retrieve(id)
Retrieve details for a specific transfer recipient.
TransferRecipientRetrieveResponse
client.transfer_recipients.list(**params)
List all transfer recipients.
TransferRecipientListResponse
client.transfer_recipients.create_bank_account(**params)
Create a new bank account transfer recipient.
TransferRecipientCreateBankAccountResponse
client.transfer_recipients.create_mobile_money(**params)
Create a new mobile money transfer recipient.
TransferRecipientCreateMobileMoneyResponse
Transfers
Send funds to bank accounts or mobile money wallets. Types:TransferRetrieveResponse, TransferListResponse, TransferGetStatusByReferenceResponse, TransferInitiateBankTransferResponse, TransferInitiateMobileMoneyTransferResponse
Methods
client.transfers.retrieve(id)
Retrieve details for a specific transfer.
TransferRetrieveResponse
client.transfers.list(**params)
List all transfers.
TransferListResponse
client.transfers.get_status_by_reference(reference)
Get the status of a transfer by its reference.
TransferGetStatusByReferenceResponse
client.transfers.initiate_bank_transfer(**params)
Initiate a bank transfer.
TransferInitiateBankTransferResponse
client.transfers.initiate_mobile_money_transfer(**params)
Initiate a mobile money transfer.
TransferInitiateMobileMoneyTransferResponse
Collections
Accept mobile money payments from customers. Types:CollectionRetrieveResponse, CollectionListResponse, CollectionGetStatusByReferenceResponse, CollectionInitiateMobileMoneyCollectionResponse
Methods
client.collections.retrieve(id)
Retrieve details for a specific collection.
CollectionRetrieveResponse
client.collections.list(**params)
List all collections.
CollectionListResponse
client.collections.get_status_by_reference(reference)
Get the status of a collection by its reference.
CollectionGetStatusByReferenceResponse
client.collections.initiate_mobile_money_collection(**params)
Initiate a mobile money collection.
CollectionInitiateMobileMoneyCollectionResponse
Transactions
View and manage transaction history. Types:TransactionRetrieveResponse, TransactionListResponse
Methods
client.transactions.retrieve(id)
Retrieve details for a specific transaction.
TransactionRetrieveResponse
client.transactions.list(**params)
List all transactions.
TransactionListResponse
Webhooks
Configure endpoints to receive real-time event notifications. Types:WebhookCreateResponse, WebhookUpdateResponse, WebhookListResponse, WebhookGetDeliveriesResponse, WebhookListEventsResponse, WebhookRotateSecretResponse
Methods
client.webhooks.create(**params)
Register a new webhook endpoint.
WebhookCreateResponse
client.webhooks.update(id, **params)
Update an existing webhook.
WebhookUpdateResponse
client.webhooks.list()
List all registered webhooks.
WebhookListResponse
client.webhooks.deactivate(id)
Deactivate a webhook.
BilaResponse
client.webhooks.get_deliveries(id, **params)
Get delivery history for a specific webhook.
WebhookGetDeliveriesResponse
client.webhooks.list_events()
List all supported webhook events.
WebhookListEventsResponse
client.webhooks.rotate_secret(id)
Rotate the signing secret for a webhook.
WebhookRotateSecretResponse
Banks
Utilities for listing supported financial institutions. Types:BankListResponse
Methods
client.banks.list(**params)
List supported banks for a specific country.
BankListResponse
Resolve
Utilities for verifying account details. Types:ResolveBankAccountResponse, ResolveMobileMoneyResponse
Methods
client.resolve.bank_account(**params)
Verify the owner of a bank account.
ResolveBankAccountResponse
client.resolve.mobile_money(**params)
Verify mobile money details.
ResolveMobileMoneyResponse
Async Usage
ImportAsyncBila instead of Bila and use await with each API call. Functionality between the synchronous and asynchronous clients is otherwise identical.
Error Handling
When the library is unable to connect to the API, a subclass ofusebila.APIConnectionError is raised. When the API returns a non-success status code (4xx or 5xx), a subclass of usebila.APIStatusError is raised, containing status_code and response properties. All errors inherit from usebila.APIError.
| Status Code | Error Type |
|---|---|
| 400 | BadRequestError |
| 401 | AuthenticationError |
| 403 | PermissionDeniedError |
| 404 | NotFoundError |
| 422 | UnprocessableEntityError |
| 429 | RateLimitError |
| >=500 | InternalServerError |
| N/A | APIConnectionError |
Type Definitions
Every API method has typed request params and responses. Types are available fromusebila.types:
| Kind | Pattern | Example |
|---|---|---|
| Response | {Resource}{Action}Response | TransferRetrieveResponse |
| Request params | {Resource}{Action}Params | WebhookCreateParams |
Best Practices
Use Environment Variables
Store API credentials in environment variables, never in source code. Consider using python-dotenv to load
BILA_API_KEY from a .env file.Implement Webhook Signature Verification
Always verify webhook signatures to ensure events are legitimately from Bila and haven’t been tampered with.
Next Steps
SDK Quickstart
Complete integration guide with examples
Transfers
Learn about initiating transfers
Webhooks
Set up webhook notifications
API Reference
Complete REST API documentation
