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 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.1.tar.gz (5.9 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.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: leja_recharge_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 5.9 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.1.tar.gz
Algorithm Hash digest
SHA256 07ba85462e6c082f1f5b4fd4312a808362cb05cd2bf453092f54189843c75601
MD5 19cdde06df0360cede3ee8228b51dafd
BLAKE2b-256 1e409315a17a8d15e58beb103b31f34571b21337e529e5aa3329591131b5b853

See more details on using hashes here.

File details

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

File metadata

  • Download URL: leja_recharge_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 31ee7ccaf24a563c7d20cf26b6c91b770f8009aac31d924fe0b06cd7a8d4f966
MD5 ab2252da57e42628633bc74c223f54fc
BLAKE2b-256 f0c57f14826d8dc40a4b43df403066fe8bb0f25523a474e97f2ff14422fc7d09

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