A multilanguage SDK for the Safaricom M-Pesa Daraja API (STK Push, STK Query, OAuth)
# M-Pesa Daraja SDK
A production-grade SDK for the Safaricom **M-Pesa Daraja API** in three languages — Go, Python, and TypeScript — sharing one contract: identical wire behaviour, identical test vectors, and identical safety rules. All nine business endpoints are covered (STK Push, STK Query, B2C payouts, C2B register/simulate, Transaction Status, Reversal, Account Balance, Dynamic QR) plus OAuth token lifecycle management.
## Requirements & installation
| Language | Version | Install | Import | Runtime deps |
|------------|----------|--------------------------------|-----------------------------------------|---------------------------------------|
| Go | 1.22+ | `go get
github.com` | `import mpesa "
github.com"` | none (stdlib only) |
| Python | 3.11+ | `pip install mpesa-sdk` | `import mpesa` | `requests`, `cryptography` |
| TypeScript | Node ≥20 | `npm install @mpesa-sdk/core` | `from "@mpesa-sdk/core"` | none (native `fetch` + `node:crypto`) |
## Getting credentials
1. Create an app at developer.safaricom.co.ke and select the products you need (Lipa na M-Pesa Online, B2C, …).
2. Copy the app's **Consumer Key** and **Consumer Secret** — they authenticate every OAuth token request.
3. Sandbox passkeys are **public test values**, published on the portal's *Test Credentials* page.
4. Export the four values as environment variables (table below).
5. Production additionally requires live credentials, HTTPS callback URLs and gateway IP whitelisting — follow the go-live checklist.
6. Initiator-based APIs (B2C et al.) need the per-environment certificate — sandbox ≠ production (`assets/certs/`).
## Configuration
| Variable | Purpose | Notes …