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.3.tar.gz (13.3 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.3-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mobiska-0.1.3.tar.gz
  • Upload date:
  • Size: 13.3 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.3.tar.gz
Algorithm Hash digest
SHA256 ee4d8d073eb0bd55f4f4198a85411aeb4bb7404201de7ef52493579a03c1cecd
MD5 ccf4ebe5b5bd7c99c60ddcfee3a2332f
BLAKE2b-256 ee2e7bbab92fe4e5b2dfbffd2a86b16552ec43441cb0dd5ca46cc1f2c04739de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mobiska-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7c12db379fae5008052de14a7803e883c68cb4abfbc10aa6e7677dcd45c94d78
MD5 e3e20977ed73e97820f6fc833365ce5c
BLAKE2b-256 d43f9a8257b02c3d48325bab4525ac7adf90fa894153fc7e3826219cccb38ba7

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