Skip to main content

Python SDK for the Mobiska REST API

Project description

Mobiska Python SDK

The official Python SDK for the Mobiska REST API — payments and SMS for businesses across Africa.

Installation

pip install mobiska

Quick Start

Configuration

Credentials can be provided via keyword arguments or environment variables:

MOBISKA_USER_NAME=your_client_key
MOBISKA_PASSWORD=your_secret_key
MOBISKA_SERVICE_ID=1
MOBISKA_SMS_SENDER_ID=YourSender      # SMS only
MOBISKA_API_URL=https://api.mobiska.com  # optional, this is the default

SMS

from mobiska import InitSMS

# Uses env vars when no arguments are passed
sms = InitSMS()

# Or pass credentials explicitly
sms = InitSMS(
    username="your_client_key",
    password="your_secret_key",
    service_id=1,
    sender_id="YourSender",
)

# Send a message
response = sms.send_sms("0540000000", "Welcome to Mobiska!")
print(response["response_code"])

# Send to multiple recipients
sms.send_sms(["0540000000", "0200000000"], "Batch message")

# Check balance
balance = sms.check_balance()
print(balance["response_data"]["sms_balance"])

Payments

from mobiska import InitPayment

payment = InitPayment(
    username="your_client_key",
    password="your_secret_key",
    service_id=2,
)

# Make a payment
result = payment.make_payment(
    reference="Order #123",
    nickname="MyShop",
    transaction_id="txn_001",
    trans_type="CTM",
    customer_number="0541840988",
    nw="MTN",
    amount=100,
    payment_option="MOM",
    callback_url="https://example.com/webhook",
    currency_code="GHS",
)

# Check transaction status
status = payment.check_transaction_status("txn_001")
print(status["response_data"]["status"])

# Account lookup (single)
info = payment.payment_account_lookup(pan="0541840988", nw="MTN")
print(info["response_data"]["name"])

# Account lookup (batch)
accounts = payment.payment_account_lookup(accounts=[
    {"pan": "0541840988", "nw": "MTN"},
    {"pan": "0201234567", "nw": "VOD"},
])

Advanced options

Both InitSMS and InitPayment accept timeout, retry_count, and retry_delay:

sms = InitSMS(timeout=10, retry_count=3, retry_delay=0.5)

Error Handling

from mobiska import (
    AuthenticationError,
    NotFoundError,
    RateLimitError,
    ValidationError,
    APIError,
)

try:
    payment.make_payment(...)
except ValidationError as e:
    print(f"Invalid input: {e}")
except AuthenticationError:
    print("Check your credentials.")
except RateLimitError:
    print("Slow down — rate limit hit.")
except APIError as e:
    print(f"Server error ({e.status_code}): {e}")

Development

# Create a virtual environment and install
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black mobiska tests

# Lint
ruff check mobiska tests

License

MIT

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

mobiska-0.1.1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

mobiska-0.1.1-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mobiska-0.1.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for mobiska-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c4f1a8a82e2bb552097f8041a48ca7fccc0cf9bedd8c6565b3f76a9c77ecb463
MD5 e2e83f6dee92c3aff597590ffa9b677e
BLAKE2b-256 738cf6c5f73dae454775149794ec0498f125833da241da3fd5a5cd769689b075

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mobiska-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for mobiska-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aa82f1a31384343df8c0559d26bb2eee51273edb34fdffe20391db7643ee3b62
MD5 ba5d753c7b5d2fbccccdc7eac03791c4
BLAKE2b-256 7a643214cea70f46ca0b83d013bf02c5dd0fbc202cb447d86cfa1bfa7f44172a

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