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

Uploaded Python 3

File details

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

File metadata

  • Download URL: leja_recharge_sdk-0.1.6.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.6.tar.gz
Algorithm Hash digest
SHA256 f0da7a3559733282148a9930cb596a115e7a96b84f691bba0427cdcf289be849
MD5 85718f209d8f96490a9d24daa5bd2dc7
BLAKE2b-256 027fe724625814668c4d638f57d3c47aaa614087095ee8f2a7f7434efc0d7893

See more details on using hashes here.

File details

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

File metadata

  • Download URL: leja_recharge_sdk-0.1.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 3467e9d9c246b2338189a94e34b7180b9f0696590d0e37e4a74f7264b3ceeb52
MD5 08503be46ae23ad289ca8c488d758b4c
BLAKE2b-256 83a0a991eaa5e5e2ed52fffbd2f27c6c2ae21c5d2d86fb3c83cc5068db6e587f

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