Skip to main content

Python SDK for the KulmiPay API

Project description

KulmiPay Python SDK

Python SDK for the KulmiPay API. Use it to create hosted checkout sessions, collect M-Pesa and PesaLink payments, send payouts, manage wallets, and create or retrieve refunds.

Install

pip install kulmipay

Configure

Use sandbox credentials with sandbox=True while testing. Use live credentials with the default live host.

from kulmipay import APIService

service = APIService(
    token="ISSecretKey_live_xxxxxxxxxxxxxxxx",
    publishable_key="ISPubKey_live_xxxxxxxxxxxxxxxx",
)

sandbox_service = APIService(
    token="ISSecretKey_test_xxxxxxxxxxxxxxxx",
    publishable_key="ISPubKey_test_xxxxxxxxxxxxxxxx",
    sandbox=True,
)

For self-hosted deployments, pass base_url:

service = APIService(
    token="YOUR_SECRET_KEY",
    publishable_key="YOUR_PUBLIC_KEY",
    base_url="https://payments.example.com/api/v1",
)

Checkout

checkout = service.collect.checkout(
    amount=1500,
    currency="KES",
    email="customer@example.com",
    phone_number="254712345678",
    api_ref="ORDER-1001",
    redirect_url="https://merchant.example/thank-you",
    unique_api_ref=True,
)

print(checkout["url"])

M-Pesa STK Push

response = service.collect.mpesa_stk_push(
    phone_number="254712345678",
    amount="1500.00",
    api_ref="ORDER-1001",
    mobile_tarrif="BUSINESS-PAYS",
)

invoice_id = response["invoice"]["invoice_id"]

PesaLink Collection

response = service.collect.pesalink(
    amount="5000.00",
    api_ref="ORDER-BANK-1001",
    email="customer@example.com",
    first_name="Jane",
    last_name="Doe",
    bank_tarrif="BUSINESS-PAYS",
)

Payment Status

status = service.collect.status(invoice_id=invoice_id)
print(status)

Send Money

transactions = [
    {
        "name": "Jane Doe",
        "account": "254712345678",
        "amount": "1000",
        "narrative": "Refund",
        "idempotency_key": "refund-1001",
    }
]

file = service.transfer.mpesa(
    currency="KES",
    transactions=transactions,
    requires_approval="YES",
)

approval = service.transfer.approve({
    "tracking_id": file["tracking_id"],
    "transactions": file["transactions"],
})

status = service.transfer.status(file["tracking_id"])

Supported providers:

Method Provider
service.transfer.mpesa(...) MPESA-B2C
service.transfer.mpesa_b2b(...) MPESA-B2B
service.transfer.bank(...) PESALINK
service.transfer.p2p(...) P2P

Wallets

wallets = service.wallets.retrieve()

wallet = service.wallets.create(
    currency="KES",
    label="Payroll Wallet",
    can_disburse=True,
)

transactions = service.wallets.transactions(wallet["wallet_id"])

Refunds

Refunds use the chargebacks endpoint internally.

refund = service.refunds.create(
    invoice_id="GQ7KZ2XPNM",
    amount="1500.00",
    reason="Duplicate payment",
)

refunds = service.refunds.retrieve()
one_refund = service.refunds.details(refund["chargeback_id"])

Error Handling

The SDK raises KulmiPayBadRequest, KulmiPayUnauthorized, KulmiPayNotAllowed, or KulmiPayServerError for common API errors.

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

kulmipay-1.0.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

kulmipay-1.0.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file kulmipay-1.0.0.tar.gz.

File metadata

  • Download URL: kulmipay-1.0.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for kulmipay-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1551dd408cae81bde9c58b695d0568bc2dc0a2fb5d47058698d57b184ae790ec
MD5 09d57a3fd0e6d345aab05db0180bf0da
BLAKE2b-256 96ca90f898c2eac0d4498e0ab42579ef20ac3f2f3c0c499aeded022fada56590

See more details on using hashes here.

File details

Details for the file kulmipay-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: kulmipay-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for kulmipay-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81cec1ed151bebadd282f8a9ca5b5891fb57dca02cb14bcc21b03336a6391cc6
MD5 161c9cd11d26f644b6998771294c8d77
BLAKE2b-256 a3168da7cb35a333838a90a43d733461771d30036fe1fdf98631e95be4097033

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