Skip to main content

Python SDK for Leja Recharge API

Project description

Leja Recharge Python SDK

Python Package CI/CD

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_sdk 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 errors
  • AuthenticationError: Raised when authentication fails
  • ValidationError: Raised when input validation fails
  • APIError: Raised when the API returns an error response
  • NetworkError: Raised when network communication fails

Models

The SDK provides type-safe models for all API responses:

  • AirtimeRecipient: Model for airtime purchase recipients
  • Transaction: Model for transaction details
  • Balance: Model for account balance
  • Country: Model for supported country information
  • PaginatedResponse: Generic model for paginated responses

Development

  1. Clone the repository

    git clone https://github.com/Asilimia/leja-recharge-py-sdk.git
    cd leja-recharge-py-sdk
    
  2. Install dependencies:

    poetry install
    
  3. 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 fixtures
  • tests/test_client.py: Client functionality tests
  • tests/test_models.py: Data model tests
  • tests/test_exceptions.py: Exception handling tests

Publishing

To publish a new version of the package:

  1. 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
    
  2. Run tests to ensure everything is working:

    poetry run pytest
    
  3. 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
    
  4. 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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

leja_recharge_sdk-0.1.5.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

leja_recharge_sdk-0.1.5-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file leja_recharge_sdk-0.1.5.tar.gz.

File metadata

  • Download URL: leja_recharge_sdk-0.1.5.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

Hashes for leja_recharge_sdk-0.1.5.tar.gz
Algorithm Hash digest
SHA256 c387f99413b1ab40e8a888a7b74c813dd3f7e2545aa194db1cecc0a08fcf164a
MD5 16fc3c7d504024e50cae80e86507bd00
BLAKE2b-256 25175a1a46e6d9d5887165b40237be092e4247505fe067564fdfedcc94408a02

See more details on using hashes here.

File details

Details for the file leja_recharge_sdk-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: leja_recharge_sdk-0.1.5-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

Hashes for leja_recharge_sdk-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b444ca3edec615009237495770b41a1e64c8cc73f630019e916f0ace49811b5a
MD5 b79fd5e86a54e9d611c5c4a709eac6a6
BLAKE2b-256 96975f5448d709f6586fbd0c637b8bb698b0dda5c1cd36267588687fda9cd117

See more details on using hashes here.

Supported by

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