Python SDK for Leja Recharge API
Project description
Leja Recharge Python SDK
A Python SDK for interacting with the Leja Recharge API.
Documentation
Take a look at the API docs here
Installation
pip install leja-recharge-sdk
Authentication
The SDK uses Basic Authentication with your Client ID and API key (Both found on the your dashboard). You'll need both credentials to initialize the client:
from leja_recharge import LejaRechargeClient
# Initialize the client with your credentials
client = LejaRechargeClient(
client_id="your_client_id",
api_key="your_api_key"
)
Quick Start
from leja_recharge_sdk import LejaRechargeClient, AirtimeRecipient
# Initialize the client with your credentials
client = LejaRechargeClient(
client_id="your_client_id",
api_key="your_api_key"
)
# Purchase airtime
recipients = [
AirtimeRecipient(
phone_number="+254712345678",
amount=10.0,
country="KE"
)
]
transaction = client.purchase_airtime(
phone_number="+254712345678",
recipients=recipients,
is_async=True,
callback_url="https://your-callback-url.com/webhook"
)
# Get transaction details
transaction_details = client.get_transaction(tracking_id=transaction.tracking_id)
# Get account balance
balance = client.get_balance()
# Get supported countries
countries = client.get_countries(page=1, limit=20)
Features
- Purchase airtime for multiple recipients
- Get transaction details
- Check account balance
- List supported countries
- Async support for airtime purchases
- Webhook callbacks for async transactions
- Comprehensive error handling
- Type hints for better IDE support
- Pagination support for listing endpoints
Error Handling
The SDK provides custom exceptions for different error scenarios:
from leja_recharge.exceptions import (
LejaRechargeError,
AuthenticationError,
ValidationError,
APIError,
NetworkError
)
try:
client = LejaRechargeClient(
client_id="invalid_client_id",
api_key="invalid_api_key"
)
except AuthenticationError as e:
print(f"Authentication failed: {e}")
Exception Types
LejaRechargeError: Base exception class for all SDK errorsAuthenticationError: Raised when authentication failsValidationError: Raised when input validation failsAPIError: Raised when the API returns an error responseNetworkError: Raised when network communication fails
Models
The SDK provides type-safe models for all API responses:
AirtimeRecipient: Model for airtime purchase recipientsTransaction: Model for transaction detailsBalance: Model for account balanceCountry: Model for supported country informationPaginatedResponse: Generic model for paginated responses
Development
-
Clone the repository
git clone https://github.com/Asilimia/leja-recharge-py-sdk.git cd leja-recharge-py-sdk
-
Install dependencies:
poetry install -
Run tests:
# Run all tests poetry run pytest # Run tests with coverage report poetry run pytest --cov=leja_recharge_sdk # Run tests verbosely poetry run pytest -v
Testing
The test suite includes:
- Unit tests for all SDK functionality
- Mock tests for API interactions
- Model validation tests
- Error handling tests
- Integration test examples
Test files are organized as follows:
tests/conftest.py: Shared pytest fixturestests/test_client.py: Client functionality teststests/test_models.py: Data model teststests/test_exceptions.py: Exception handling tests
Publishing
To publish a new version of the package:
-
Update version numbers in relevant files:
# Update version in pyproject.toml or setup.py # Update version in __init__.py if applicable # Update CHANGELOG.md with your changes
-
Run tests to ensure everything is working:
poetry run pytest
-
Create and push a new Git tag:
# Create a new tag git tag -a v1.0.0 -m "Version 1.0.0" # Push the tag git push origin v1.0.0
-
The GitHub Actions workflow will automatically:
- Run tests across Python versions 3.8-3.11
- Build the package
- Publish to PyPI if all tests pass
Note: Make sure you have:
- Updated all version numbers consistently
- Added all changes to CHANGELOG.md
- Committed all changes to main branch
- Have proper PyPI credentials configured in GitHub Secrets
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT License
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file leja_recharge_sdk-0.1.2.tar.gz.
File metadata
- Download URL: leja_recharge_sdk-0.1.2.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.11.11 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f42abc360baff56a6b2c094f5551dd44bce7737c87cb8252864fb744db74673
|
|
| MD5 |
752b5eab6ac285227b4809de222c7224
|
|
| BLAKE2b-256 |
62aa6d06c297ec09e468d1535e1763cbc45e74bc33f26fc07deb07eeee7b19c1
|
File details
Details for the file leja_recharge_sdk-0.1.2-py3-none-any.whl.
File metadata
- Download URL: leja_recharge_sdk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.11.11 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4aa9448f9dd265465797672d73a3dee0cc08e485f0ae7892b89e0c2243fd1860
|
|
| MD5 |
25079e872259e578120a10bac3dc6966
|
|
| BLAKE2b-256 |
464ef5d5e53cf5a2f8644ec0c4b323a21e5e95ce961a917fa9f6b6a9b1d1a674
|