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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mobiska-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 66026da346aa41dc031ea5be562ad35d1160e3d631935eb6df66d22cae2fa8fc
MD5 4a977055b929b0e2f80168db5822351b
BLAKE2b-256 bb54857c7e6d96dda3cf8258519560c4cdb371d0f2692f984d0cbd6d9d602641

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mobiska-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab6921e895c56ea076b7d79cbd2c8ffd1d357f1d7c6f8c9b50dc5203cfedf806
MD5 637fa5c0eb83911d9cc1e8b5f5e3f167
BLAKE2b-256 2d6d542220d81dcb877a784759a7e570ef387866c19a6db6073130a78c87cd4a

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