Official Python SDK for Lipay Messaging Platform
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lipay_sdk-1.0.0.tar.gz.
File metadata
- Download URL: lipay_sdk-1.0.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e82abb3f0f0556adcdf56b4393ed51bd1127fe81ccb801dccb7a1bf07428b5b
|
|
| MD5 |
95552b8f1bcefaad2f5e9f72793adeb9
|
|
| BLAKE2b-256 |
06e5ec7f372fdc42592144e805a42026230b0be722bb246ac739a26fe12bf979
|
Provenance
The following attestation bundles were made for lipay_sdk-1.0.0.tar.gz:
Publisher:
publish-pypi.yml on Evans-musamia/LipayMessagingPlatform
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lipay_sdk-1.0.0.tar.gz -
Subject digest:
9e82abb3f0f0556adcdf56b4393ed51bd1127fe81ccb801dccb7a1bf07428b5b - Sigstore transparency entry: 1676135448
- Sigstore integration time:
-
Permalink:
Evans-musamia/LipayMessagingPlatform@ea26f6ceef90f7fb90cc436ca155668bcaf9cc26 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Evans-musamia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@ea26f6ceef90f7fb90cc436ca155668bcaf9cc26 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lipay_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: lipay_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fef1d7873a046ef0799470a08083abebafff9e8ef923db56d64f04a14624d23a
|
|
| MD5 |
3949c2d3046ee82d2f502ebf83c20176
|
|
| BLAKE2b-256 |
dd7f2ed7a28c728d9ac14d27bd6fae31008224fcf18b8e95d35071880318aa04
|
Provenance
The following attestation bundles were made for lipay_sdk-1.0.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on Evans-musamia/LipayMessagingPlatform
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lipay_sdk-1.0.0-py3-none-any.whl -
Subject digest:
fef1d7873a046ef0799470a08083abebafff9e8ef923db56d64f04a14624d23a - Sigstore transparency entry: 1676135466
- Sigstore integration time:
-
Permalink:
Evans-musamia/LipayMessagingPlatform@ea26f6ceef90f7fb90cc436ca155668bcaf9cc26 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Evans-musamia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@ea26f6ceef90f7fb90cc436ca155668bcaf9cc26 -
Trigger Event:
push
-
Statement type: