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.3.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.3-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: leja_recharge_sdk-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 a053be86c26bf0055d11c557d6bf220ce8ebabebe7f6fc1ec56fd72d1dfa888e
MD5 acdb298c00393bd28dd58befd058931c
BLAKE2b-256 bec7d9ccb3d6e43b08de50cdf31a8e9f53baf20294e5b021d3281efc9be649db

See more details on using hashes here.

File details

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

File metadata

  • Download URL: leja_recharge_sdk-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 37f3f0110beb1ea953759611caa8bcedf08189f324d5b23f6e63463e5fb631c2
MD5 40c6955d1f768545e504b1aeb25c6f14
BLAKE2b-256 a2af527f7d5e5112c90061aa92366b0206f8f6a4947af8569738b2fcfe6a5fb6

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