Skip to main content

K Khay Python SDK 🐍

Official Python SDK for the K Khay Sovereign Crypto Payment Gateway.

Accept non-custodial and custodial crypto payments (USDT, USDC, BNB, ETH, and native tokens across BSC, Polygon, Arbitrum, Base, and Ethereum) directly in your Python applications, Django, FastAPI, Flask, or background bots with zero third-party dependencies.


📦 Installation

pip install kkhay

(Requires Python 3.8 or newer)


⚡ Quick Start

1. Initialize Client

from kkhay import KkhayClient

client = KkhayClient(api_key="kkhay_live_your_api_key_here")

2. Create a Payment Invoice

response = client.create_invoice(
    price_amount=49.99,
    price_currency="USD",
    pay_network="bsc",
    pay_token="USDT",
    order_id="ORDER-9012",
    title="Annual Premium Membership",
    customer_email="merchant-customer@example.com",
    redirect_url="https://myshop.com/orders/success",
    cancel_url="https://myshop.com/cart",
)

invoice = response["invoice"]
print("Invoice ID:", invoice.id)
print("Deposit Address:", invoice.deposit_address)
print("Customer Checkout URL:", invoice.hosted_url)

3. Retrieve Invoice Status & Blockchain Proofs

data = client.get_invoice("inv_9f81a7b2")
invoice = data.invoice

print(f"Status: {invoice.status}")
for payment in data.payments:
    print(f"Received: {payment.amount_received} {invoice.pay_token}")
    print(f"Tx Hash: {payment.tx_hash} ({payment.confirmations} confirmations)")

4. List & Paginate Invoices

res = client.list_invoices(page=1, limit=10, status="FINISHED")
print(f"Total Completed Invoices: {res.total_count}")
for inv in res.items:
    print(f"- {inv.id}: ${inv.price_amount} ({inv.status})")

🔐 Webhook / IPN Verification

K Khay cryptographically signs every webhook notification using HMAC-SHA256 with your secret IPN key.

FastAPI Example

from fastapi import FastAPI, Header, HTTPException, Request
from kkhay import SignatureVerificationError, parse_webhook_event

app = FastAPI()
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=400, detail="Invalid signature")

    if event.event == "payment.finished":
        print(f"Order {event.order_id} was paid!")
        print(f"Transaction Hash: {event.tx_hash}")

    return {"status": "ok"}

Flask / Django Example

from flask import Flask, abort, request
from kkhay import SignatureVerificationError, parse_webhook_event

app = Flask(__name__)


@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, "whsec_your_secret")
    except SignatureVerificationError:
        abort(400)

    # Process order
    return "OK", 200

🛠️ Error Handling

from kkhay import KkhayApiError, KkhayClient

client = KkhayClient(api_key="invalid_key")

try:
    client.get_invoice("inv_not_exist")
except KkhayApiError as e:
    print(f"HTTP Status: {e.status}")
    print(f"Error Code: {e.code}")
    print(f"Message: {e.message}")

📄 License

MIT © K Khay

Metadata

Release files for kkhay 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kkhay 1.0.0
File Size Uploaded Provenance
kkhay-1.0.0.tar.gz 7.7 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kkhay 1.0.0
File Interpreter ABI Platform
kkhay-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.1 kB

Release files / kkhay-1.0.0.tar.gz

Download URL kkhay-1.0.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
103c19ee6ac868f76071600e59c1ba000aaeaf024940f837e6d637075f4bb7f6
BLAKE2b-256 checksum
How to use checksums
deadcf5d216c1351c45e5cfd483c14773a838bdc3dcfbeda393b55c0862877c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 6, 2026.

Transparency log

Release files / kkhay-1.0.0-py3-none-any.whl

Download URL kkhay-1.0.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb2eb14fefcaa0d451a4e7bec4f8142e415a9f39727df07c689f4135feb9e536
BLAKE2b-256 checksum
How to use checksums
5ea1b0c3d71deb520f84dc533acf86ef5ebd0d935d9a901b7bc350b66288d382
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 6, 2026.

Transparency log

Security for kkhay 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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for kkhay-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 Oct 6, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page