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

Mobiska Python SDK

The official Python SDK for the Mobiska REST API.

Installation

pip install mobiska

Quick Start

from mobiska import MobiskaClient

client = MobiskaClient(api_key="your-api-key")

# GET request
users = client.get("/users")

# POST request
new_user = client.post("/users", json={"name": "Alice"})

# PATCH request
client.patch(f"/users/{new_user['id']}", json={"name": "Alice Updated"})

# DELETE request
client.delete(f"/users/{new_user['id']}")

Error Handling

from mobiska import MobiskaClient, AuthenticationError, NotFoundError, RateLimitError

try:
    client.get("/users/999")
except AuthenticationError:
    print("Check your API key.")
except NotFoundError:
    print("Resource not found.")
except RateLimitError:
    print("Slow down — rate limit hit.")

Development

# Install with dev dependencies
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.0.tar.gz (13.6 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.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mobiska-0.1.0.tar.gz
  • Upload date:
  • Size: 13.6 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.0.tar.gz
Algorithm Hash digest
SHA256 4ffec6a628071ac9621e803241b46af9a11b200e33f813a7f85af7888e210bd7
MD5 eb86afd102493dd3909b5f3cddf067a9
BLAKE2b-256 3a8e46f96c029f73157e9c7016939cb8cb666b53629569bc662ad6f98dd433f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mobiska-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19a1ac53a03dfc6d36a66e050db95c6b094ba1d68c2be59408e1c5665e83a54c
MD5 56e44d64d0af1306ce699197d5fa2a0e
BLAKE2b-256 83dc9430495bba6ed8457f616f996d3c74cfe3227baa09d97d5717e88f9d4121

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