Python SDK
Official Python SDK

How to install and use IntaSend Python SDK

1
pip install intasend-python
Copied!

Authenticating service

Obtain your API token and Publishable key from your account i.e under Settings - API Keys panel.
1
from intasend import APIService
2
3
private_key = """-----BEGIN PRIVATE KEY-----
4
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCwhxnB5aZD6EqF....8laHwYTQdDbAlCGZB992YoHl
5
-----END PRIVATE KEY-----"""
6
7
token = "YOUR-API-TOKEN"
8
publishable_key = "YOUR-PUBLISHABLE-KEY"
9
service = APIService(token="token",publishable_key=publishable_key, private_key=private_key)
Copied!

How to generate PRIVATE KEY

Use the following helper function to generate a RSA Key for nonce signing. Keep your private_key safe and share the public key with IntaSend. Note: These key pair is required only if you are sending money.
1
from intasend.utils import generate_keys
2
3
private_key, public_key = generate_keys()
4
print(private_key)
5
print(public_key)
Copied!

Code Examples

Below are few usage examples for your reference.
1
service = APIService(token="token",publishable_key=publishable_key, private_key=private_key, test=True)
2
3
# Trigger M-Pesa STK Push
4
response = service.collect.mpesa(phone_number=2547...,
5
email="[email protected]", amount=10, narrative="Fees")
6
print(response)
7
8
# Wallets Management
9
response = service.wallets.retrieve()
10
print(response)
11
12
response = service.wallets.details(<WALLET-ID>)
13
print(response)
14
15
response = service.wallets.transactions(<WALLET-ID>)
16
print(response)
17
18
response = service.wallets.create("GBP")
19
print(response)
20
21
# Fund specific wallet
22
response = service.wallets.fund(
23
wallet_id=<WALLET-ID>, phone_number=25472.., email="[email protected]", amount=10, narrative="Fees", name="Awesome Customer")
24
print(response)
25
26
# Wallet to wallet transfers
27
response = service.wallets.intra_transfer(<WALLET-ID-1>, <WALLET-ID-2>, 1, "Charge capture")
28
print(response)
29
30
# Retrieve Chargebacks
31
response = service.chargebacks.retrieve(<CHARGEBACK-ID>)
32
print(response)
33
34
# Send money
35
transactions = [{'name': 'Awesome Customer 1', 'account': 25472.., 'amount': 10},
36
{'name': 'Awesome Customer 2', 'account': 25472.., 'amount': 10000}]
37
38
## device_id - Note device id is the PSD2 device id from the dashboard
39
response = service.transfer.mpesa(device_id=<DEVICE-ID>, currency='KES', transactions=transactions)
40
print(response)
41
42
# Check transfer status
43
status = service.transfer.status(response.get("tracking_id"))
44
print(f"Status: {status}")
45
46
47
# Create payment link
48
title = "Link title/name"
49
response = service.payment_links.create(title=title, currency="KES", amount=10)
Copied!
Last modified 2d ago