Skip to main content

Thawani Python Client

Python SDK for integrating with the Thawani Checkout API.

This package is used by ERPNext/Payments integrations and can also be used directly in standalone Python services.

Requirements

  • Python >=3.6
  • requests

Installation

From PyPI

pip install thawani

From local source (editable)

pip install -e /path/to/thawani-python

Quick Start

Get your API keys from your Thawani merchant dashboard.

import thawani

client = thawani.Client(
    secret_key="<SECRET_KEY>",
    publishable_key="<PUBLISHABLE_KEY>",
    use_sandbox=True,   # False for production
)

Backward-compatible initialization is still supported:

client = thawani.Client(data={
    "secret_key": "<SECRET_KEY>",
    "publishable_key": "<PUBLISHABLE_KEY>",
    "use_sandbox": 1,
})

Common Checkout Flow

Create a checkout session and get a payment URL:

payload = {
    "client_reference_id": "CUST-0001",
    "mode": "payment",
    "products": [
        {"name": "Online Payment", "quantity": 1, "unit_amount": "1000"}
    ],
    "success_url": "https://example.com/payment/success",
    "cancel_url": "https://example.com/payment/cancel",
}

resp = client.checkout.create(data=payload)
payment_url = client.generate_payment_link(resp)
print(payment_url)

Fetch a session status:

session = client.checkout.fetch("SESSION_ID")
print(session)

Fetch by reference id:

session = client.checkout.fetch_session_by_client_id("CLIENT_REFERENCE_ID")
print(session)

Available Resources

The client exposes these resource handlers:

  • checkout
  • customer
  • payment_intent
  • payment_method
  • payment
  • refund
  • invoice
  • order
  • payment_link
  • subscription
  • registration_link
  • card
  • token
  • transfer
  • virtual_account
  • fund_account
  • addon
  • plan
  • settlement
  • item
  • qrcode
  • utility

Each resource typically supports one or more of: create, fetch, all, edit, delete.

Error Handling

All API failures raise SDK exceptions:

  • BadRequestError
  • GatewayError
  • ServerError

Example:

from thawani.errors import BadRequestError, GatewayError, ServerError

try:
    client.checkout.fetch("invalid-session")
except BadRequestError as e:
    print("Request failed:", e)
except GatewayError as e:
    print("Gateway error:", e)
except ServerError as e:
    print("Server error:", e)

Sandbox and Production

  • Sandbox API base: https://uatcheckout.thawani.om/api/v1
  • Production API base: https://checkout.thawani.om/api/v1

use_sandbox=True switches the client to sandbox URLs.

Development

Run tests:

pytest

Format/lint according to your local project standards before publishing.

Documentation

Detailed resource docs are in documents/:

Contributing

Issues and pull requests are welcome:

Metadata

Release files for thawani 1.1.5

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

Source distribution (sdist)

Source distribution for thawani 1.1.5
File Size Uploaded Provenance
thawani-1.1.5.tar.gz 38.3 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 65.0 kB

Release files / thawani-1.1.5.tar.gz

Download URL thawani-1.1.5.tar.gz
Size 38.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b130f6aa5c82a9481395cf959bcfb1b8ac16504c6dc3d5f63b02e8329db19f82
BLAKE2b-256 checksum
How to use checksums
8e7287259575922027e88d131352e85cc67674e795f2b5c4328cda3da2328fdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.15

Release files / thawani-1.1.5-py3-none-any.whl

Download URL thawani-1.1.5-py3-none-any.whl
Size 26.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b62cfe1a4c8fc121fcf6d9a7b5b66f7f6a9b1f73aad5d3d93acc7918bcf42777
BLAKE2b-256 checksum
How to use checksums
b17a1da2548a88eb9028791cd57565e9a3fec1988418e8ab248b7e526f38d486
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.15

Security for thawani 1.1.5

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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