Lipay Python SDK
Official Python client for Lipay — the developer platform for WhatsApp messaging, routing, and Customer Service Window (CSW) management across Africa.
Use this library in your application (BrandFlow, Teacher, custom backends) to check whether the Meta 24-hour customer service window is open before sending free-text WhatsApp messages.
Installation
From PyPI (recommended):
pip install lipay-sdk
pip install "lipay-sdk[fastapi]"
Pin in requirements.txt:
lipay-sdk==1.0.0
From Git (tagged release):
pip install git+https://github.com/Evans-musamia/LipayMessagingPlatform.git@v1.0.0
TestPyPI (maintainers — sandbox):
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ lipay-sdk
Editable (local development):
git clone https://github.com/Evans-musamia/LipayMessagingPlatform.git
cd LipayMessagingPlatform
pip install -e ".[dev]"
Publishing guide: PYPI.md
Quick start
import asyncio
from lipay_sdk import LipayCswSessionGuard
async def main() -> None:
guard = LipayCswSessionGuard("https://message.lipay.store")
active = await guard.is_window_active(
customer_phone="+254700000000",
business_phone="+254711111111",
)
if active:
print("CSW open — safe to send free-text via Lipay /v1/whatsapp/send")
else:
print("CSW closed — send an approved template first")
await guard.close()
if __name__ == "__main__":
asyncio.run(main())
Configuration object (Pydantic)
For explicit control over timeouts, cache TTL, and API paths:
from lipay_sdk.csw_session_guard import LipayCswSessionGuard, LipaySdkConfig
config = LipaySdkConfig(
gateway_url="https://message.lipay.store",
local_active_ttl_seconds=180,
http_timeout_seconds=10.0,
)
guard = LipayCswSessionGuard(config)
Full status payload
status = await guard.get_session_status(
customer_phone="254700000000",
business_phone="254711111111",
)
print(status.is_communication_window_active, status.window_expires_at)
Caching behavior
The SDK implements an in-process memory guard in front of Lipay's Redis-backed GET /api/v1/switchboard/session-status endpoint.
| Event | Behavior |
|---|---|
Lipay returns active=true |
Response cached in your app process RAM for 180 seconds (configurable via LipaySdkConfig.local_active_ttl_seconds) |
| Repeat lookup within TTL | Served from local memory — no HTTP call to Lipay |
Lipay returns active=false |
Never cached — every lookup hits Lipay |
| Local TTL expires | Cache entry dropped; next lookup syncs from Lipay |
This mirrors how Twilio-style SDKs reduce read amplification: your container avoids redundant session-status traffic while the gateway remains the source of truth on Redis.
FastAPI integration
Install the optional extra:
pip install "lipay-sdk[fastapi] @ git+https://github.com/Evans-musamia/LipayMessagingPlatform.git@v1.0.0"
Wire the guard on application startup:
from contextlib import asynccontextmanager
import httpx
from fastapi import Depends, FastAPI, Request
from lipay_sdk import LipayCswSessionGuard
from lipay_sdk.csw_session_guard import LipaySdkConfig
@asynccontextmanager
async def lifespan(app: FastAPI):
http = httpx.AsyncClient(timeout=10.0)
config = LipaySdkConfig(gateway_url="https://message.lipay.store")
app.state.lipay_guard = LipayCswSessionGuard(config, http_client=http)
yield
await app.state.lipay_guard.close()
app = FastAPI(lifespan=lifespan)
def get_guard(request: Request) -> LipayCswSessionGuard:
return request.app.state.lipay_guard
@app.get("/check-window")
async def check_window(
customer_phone: str,
business_phone: str,
guard: LipayCswSessionGuard = Depends(get_guard),
):
return await guard.get_session_status(
customer_phone=customer_phone,
business_phone=business_phone,
)
API reference
LipayCswSessionGuard
| Method | Description |
|---|---|
is_window_active(customer_phone, business_phone) |
bool — CSW open for pair |
get_session_status(...) |
SessionStatus — full gateway payload |
fetch_from_lipay(...) |
Always calls Lipay (bypasses local cache) |
close() |
Close owned httpx client |
LipaySdkConfig (Pydantic)
| Field | Default | Description |
|---|---|---|
gateway_url |
required | Lipay gateway base URL |
local_active_ttl_seconds |
180 |
Local RAM cache TTL |
http_timeout_seconds |
5.0 |
HTTP client timeout |
session_status_path |
/api/v1/switchboard/session-status |
Status endpoint path |
License
MIT — see LICENSE.
Metadata
Release files for lipay-sdk 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lipay_sdk-1.0.0.tar.gz | 6.8 kB | With provenance | Details for lipay_sdk-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lipay_sdk-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for lipay_sdk-1.0.0-py3-none-any.whl |
Total release size: 13.5 kB
Release files / lipay_sdk-1.0.0.tar.gz
| Download URL | lipay_sdk-1.0.0.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e82abb3f0f0556adcdf56b4393ed51bd1127fe81ccb801dccb7a1bf07428b5b
|
|
BLAKE2b-256 checksum How to use checksums |
06e5ec7f372fdc42592144e805a42026230b0be722bb246ac739a26fe12bf979
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 30, 2026.
Transparency logRelease files / lipay_sdk-1.0.0-py3-none-any.whl
| Download URL | lipay_sdk-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fef1d7873a046ef0799470a08083abebafff9e8ef923db56d64f04a14624d23a
|
|
BLAKE2b-256 checksum How to use checksums |
dd7f2ed7a28c728d9ac14d27bd6fae31008224fcf18b8e95d35071880318aa04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 30, 2026.
Transparency logSecurity for lipay-sdk 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for lipay_sdk-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.