kkhay-python
Official Python SDK for K Khay — The Non-Custodial Crypto Payment Gateway
Accept cryptocurrency payments across 190+ blockchain networks and 500+ tokens (EVM, Bitcoin, Solana, TON, Tron, and XRPL) with zero custody and automatic direct-to-wallet settlement. Works natively with FastAPI, Django, Flask, Celery, or background automation bots with zero external dependencies.
⚡ Key Highlights
- 🛡️ 100% Non-Custodial: Payments settle directly to your destination blockchain address in seconds. K Khay never holds your private keys or customer funds.
- 🌐 190+ Networks Supported:
- EVM Networks: BNB Smart Chain (
bsc), Polygon (polygon), Arbitrum (arbitrum), Base (base), Ethereum (eth), Optimism (optimism), Avalanche (avalanche), and 180+ more. - UTXO Networks: Bitcoin (
btc), Dogecoin (doge), Litecoin (ltc), Bitcoin Cash (bch). - High-Throughput Chains: Solana (
sol), TON (ton), Tron (trx), XRP Ledger (xrp).
- EVM Networks: BNB Smart Chain (
- 🪙 500+ Cryptocurrencies: Native coins and tokens (USDT, USDC, BTC, ETH, SOL, TON, BNB, DOGE, XRP, TRX, LTC, and more).
- 🔗 Branded Hosted Checkouts: Instant hosted checkout URLs with dynamic QR codes, live blockchain polling, and wallet deep links.
- 🔔 Cryptographic Webhooks: Timing-safe HMAC-SHA256 signature verification (
x-kkhay-signatureviahmac.compare_digest). - 🪶 Zero External Dependencies: Pure Python standard library implementation (
urllib.request,hmac,hashlib,json,dataclasses).
📦 Installation
pip install kkhay
(Requires Python 3.9 or newer)
🚀 Quickstart
1. Initialize the Client
Obtain your API Key from the K Khay Gateway Dashboard.
from kkhay import KkhayClient
client = KkhayClient(api_key="kkhay_live_your_api_key_here")
Custom base URL and timeout can be configured:
client = KkhayClient(
api_key="kkhay_live_your_api_key_here",
base_url="https://api.kkhay.com",
timeout=30.0,
)
2. Create a Crypto Payment Invoice
from kkhay import KkhayClient, InvoiceTypeEnum
client = KkhayClient(api_key="kkhay_live_your_api_key_here")
response = client.create_invoice(
amount=49.99,
currency="USD",
pay_network="bsc", # or "polygon", "solana", "bitcoin", "tron", etc.
pay_token="USDT", # or "USDC", "BTC", "ETH", "SOL", "TON", etc.
order_id="ORD-9012",
title="Pro Tier Membership",
customer_email="buyer@example.com",
redirect_url="https://myshop.com/success",
cancel_url="https://myshop.com/cart",
type=InvoiceTypeEnum.PAYMENT,
)
invoice = response["invoice"]
print("Invoice ID:", invoice.id)
print("Deposit Address:", invoice.deposit_address)
print("Checkout URL:", invoice.hosted_url)
3. Retrieve Invoice Status & Blockchain Confirmations
data = client.get_invoice("0192e2b3-5776-791b-8524-77a834164b12")
invoice = data.invoice
print(f"Status: {invoice.status}") # WAITING, PAID, EXPIRED, CANCELED
for payment in data.payments:
print(f"Received: {payment.amount_received} on tx {payment.tx_hash}")
print(f"Confirmations: {payment.confirmations}")
4. List & Paginate Invoices
from kkhay import InvoiceStatusEnum
res = client.list_invoices(
page=1,
limit=10,
status=InvoiceStatusEnum.PAID,
)
print(f"Total Settled: {res.total_count}")
for inv in res.items:
print(f"- {inv.id}: ${inv.amount} {inv.currency} ({inv.status})")
5. Check API Health
health = client.check_health()
print("Gateway API Status:", health.get("status"))
🔐 Webhook / IPN Verification
K Khay cryptographically signs every webhook notification using HMAC-SHA256 with your secret IPN key.
FastAPI Example
import os
from fastapi import FastAPI, Header, HTTPException, Request
from kkhay import (
SignatureVerificationError,
WebhookEventTypeEnum,
parse_webhook_event,
)
app = FastAPI()
IPN_SECRET = os.getenv("KKHAY_IPN_SECRET", "whsec_your_secret_key")
@app.post("/api/webhooks/kkhay")
async def handle_kkhay_webhook(
request: Request,
x_kkhay_signature: str = Header(None),
):
body = await request.body()
try:
event = parse_webhook_event(
raw_body=body,
signature=x_kkhay_signature,
ipn_secret=IPN_SECRET,
)
except SignatureVerificationError:
raise HTTPException(status_code=401, detail="Invalid signature")
if event.event == WebhookEventTypeEnum.PAYMENT_PAID or event.event == WebhookEventTypeEnum.PAYMENT_FINISHED:
print(f"Order {event.order_id} fulfilled!")
print(f"Blockchain Tx: {event.tx_hash}")
return {"status": "ok"}
Django / Flask Example
import os
from flask import Flask, abort, request
from kkhay import (
SignatureVerificationError,
WebhookEventTypeEnum,
parse_webhook_event,
)
app = Flask(__name__)
IPN_SECRET = os.getenv("KKHAY_IPN_SECRET", "whsec_your_secret")
@app.route("/webhooks/kkhay", methods=["POST"])
def webhook():
raw_body = request.get_data()
sig = request.headers.get("x-kkhay-signature")
try:
event = parse_webhook_event(raw_body, sig, IPN_SECRET)
except SignatureVerificationError:
abort(401)
if event.event in (WebhookEventTypeEnum.PAYMENT_PAID, WebhookEventTypeEnum.PAYMENT_FINISHED):
# Fulfill order in database
pass
return {"ok": True}, 200
📚 Constants & Enums
Invoice Status (InvoiceStatusEnum)
Matches PostgreSQL schema enum values:
| Constant | Value | Description |
|---|---|---|
InvoiceStatusEnum.WAITING |
'WAITING' |
Awaiting customer payment on blockchain |
InvoiceStatusEnum.PAID |
'PAID' |
Transaction confirmed and settled |
InvoiceStatusEnum.EXPIRED |
'EXPIRED' |
Payment window closed without full payment |
InvoiceStatusEnum.CANCELED |
'CANCELED' |
Invoice explicitly voided or canceled |
Invoice Type (InvoiceTypeEnum)
| Constant | Value | Description |
|---|---|---|
InvoiceTypeEnum.PAYMENT |
'PAYMENT' |
Standard e-commerce payment |
InvoiceTypeEnum.DONATION |
'DONATION' |
Open-amount contribution |
InvoiceTypeEnum.SUBSCRIPTION |
'SUBSCRIPTION' |
Recurring subscription billing |
Webhook Event Types (WebhookEventTypeEnum)
| Constant | Value | Description |
|---|---|---|
WebhookEventTypeEnum.PAYMENT_PAID |
'payment.paid' |
Payment confirmed on blockchain |
WebhookEventTypeEnum.PAYMENT_FINISHED |
'payment.finished' |
Invoice completed and finalized |
WebhookEventTypeEnum.PAYMENT_CONFIRMING |
'payment.confirming' |
Transaction detected, awaiting confirmations |
WebhookEventTypeEnum.PAYMENT_FAILED |
'payment.failed' |
Transaction failed on-chain |
WebhookEventTypeEnum.INVOICE_CANCELED |
'invoice.canceled' |
Invoice was canceled |
🌐 Supported Blockchains (190+ Networks)
| Network | Code | Type | Popular Tokens |
|---|---|---|---|
| BNB Smart Chain | bsc |
EVM | USDT, USDC, BNB, DAI |
| Polygon | polygon |
EVM | USDT, USDC, POL, WETH |
| Arbitrum One | arbitrum |
EVM (L2) | USDT, USDC, ARB, ETH |
| Base | base |
EVM (L2) | USDC, ETH, DAI |
| Ethereum | eth |
EVM (L1) | USDT, USDC, ETH, DAI |
| Solana | solana / sol |
High-Throughput | SOL, USDT, USDC |
| TON Network | ton |
High-Throughput | TON, USDT |
| Tron | tron / trx |
TRC-20 | TRX, USDT, USDC |
| Bitcoin | bitcoin / btc |
UTXO | BTC |
| XRP Ledger | xrpl / xrp |
Ledger | XRP |
| Dogecoin | dogecoin / doge |
UTXO | DOGE |
| Litecoin | litecoin / ltc |
UTXO | LTC |
And 180+ additional networks dynamically routed through K Khay.
📄 License
MIT © K Khay
Metadata
Release files for kkhay 1.0.4
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 | |
|---|---|---|---|---|
| kkhay-1.0.4.tar.gz | 10.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kkhay-1.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.2 kB
Release files / kkhay-1.0.4.tar.gz
| Download URL | kkhay-1.0.4.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
068db1273bb3209f4d6de51c94d075079c574f74395bbf1aab02ccd3ee3ae589
|
|
BLAKE2b-256 checksum How to use checksums |
dfbbdeb96502b682e1959b1861611616fec22fd718ab17de191ffbf209fb8d17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 25, 2026.
Transparency logRelease files / kkhay-1.0.4-py3-none-any.whl
| Download URL | kkhay-1.0.4-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6eaa3909724d4f28322b93f00bc744eb5b20d53e6dcf326f061343eddeec812
|
|
BLAKE2b-256 checksum How to use checksums |
60e729196d1f3c24541d99dc2cfa166139ab7918129ed07025708088ea10629d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 25, 2026.
Transparency logSecurity for kkhay 1.0.4
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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for kkhay-1.0.4.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 Oct 25, 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.