Skip to main content

Official Python SDK for Granthe — institutional liquidity rail for crypto settlement

Project description

granthe

Official Python SDK for Granthe — institutional liquidity rail for crypto settlement.

PyPI Python

Install

pip install granthe

Quick Start

from granthe import Granthe

granthe = Granthe(api_key="vf_live_...", webhook_secret="whsec_...")

# Create a payment invoice
invoice = granthe.invoices.create(
    amount=100.00,
    currency="USDT",
    network="tron",
    description="Premium Plan",
    customer_email="buyer@example.com",
)
print(f"Pay to: {invoice.wallet_address}")
print(f"Status: {invoice.status}")

# Request a payout
payout = granthe.payouts.create(
    amount=50.00,
    currency="USDT",
    network="tron",
    destination="TXyz...recipientAddress",
)
print(f"Payout ID: {payout.id}")

Async Support

from granthe import AsyncFlow

async with AsyncFlow(api_key="vf_live_...") as flow:
    invoice = await granthe.invoices.create(
        amount=100, currency="USDT", network="ethereum",
    )

Resources

Invoices

# Create
invoice = granthe.invoices.create(amount=100, currency="USDT", network="tron")

# Get by ID
invoice = granthe.invoices.get("inv_abc123")

# List with filters
result = granthe.invoices.list(status="paid", page=1, limit=20)
for inv in result.items:
    print(inv.id, inv.amount, inv.status)

# Cancel
granthe.invoices.cancel("inv_abc123")

Payouts

# Single payout
payout = granthe.payouts.create(
    amount=50, currency="USDT", network="tron",
    destination="TXyz...addr",
)

# Batch payout
payouts = granthe.payouts.create_batch([
    {"amount": 50, "currency": "USDT", "network": "tron", "destination_address": "TXyz..."},
    {"amount": 25, "currency": "USDT", "network": "tron", "destination_address": "TAbc..."},
])

# Check status
payout = granthe.payouts.get("pout_abc123")

Wallets

# Generate a new deposit wallet
wallet = granthe.wallets.generate(network="ethereum", currency="USDT")
print(wallet.address)

# List wallets
result = granthe.wallets.list(network="tron")

# Check balance
wallet = granthe.wallets.balance("wal_abc123")

Swaps

# Get a quote
quote = flow.swaps.quote("BTC", "USDT", amount=0.01)
print(f"Rate: {quote.rate}, You get: {quote.to_amount} USDT")

# Execute swap
swap = flow.swaps.create("BTC", "USDT", amount=0.01)

Webhooks

from granthe import Granthe, InvalidSignatureError

granthe = Granthe(api_key="vf_live_...", webhook_secret="whsec_...")

# In your webhook handler:
def handle_webhook(request):
    payload = request.body
    signature = request.headers["X-Granthe-Signature"]

    try:
        event = flow.webhooks.verify(payload, signature)
    except InvalidSignatureError:
        return {"error": "Invalid signature"}, 400

    if event.type == "invoice.paid":
        invoice_id = event.data["id"]
        print(f"Invoice {invoice_id} paid!")

    return {"status": "ok"}

Error Handling

from granthe import Granthe, FlowError, AuthenticationError, RateLimitError

granthe = Granthe(api_key="vf_live_...")

try:
    invoice = granthe.invoices.create(amount=100, currency="USDT", network="tron")
except AuthenticationError:
    print("Bad API key")
except RateLimitError as e:
    print(f"Rate limited, retry after {e.retry_after}s")
except FlowError as e:
    print(f"Error: {e.message} (code={e.code}, status={e.status})")

Configuration

granthe = Granthe(
    api_key="vf_live_...",
    webhook_secret="whsec_...",      # For webhook verification
    base_url="https://api.granthe.io/api/v1",  # Default
    timeout=30.0,                     # Request timeout in seconds
)

Supported Networks

Bitcoin, Ethereum, Tron, BNB Chain, Solana, Ripple, Polygon, Avalanche, Dogecoin, Litecoin, TON, and more.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

granthe-0.6.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

granthe-0.6.0-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file granthe-0.6.0.tar.gz.

File metadata

  • Download URL: granthe-0.6.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for granthe-0.6.0.tar.gz
Algorithm Hash digest
SHA256 624506cd042b75c7f916b68f186b3ef31e68b4634f78810e6519e624d01812c2
MD5 720d84ea17154071f14cd81e1b4e4b6e
BLAKE2b-256 09e9c3d4b247fa5f50c4f8f1612bdc6ad126e63b635cd65e52dfcc7b3e1afbad

See more details on using hashes here.

File details

Details for the file granthe-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: granthe-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for granthe-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1df70653500048a9cd1b52db626f0ad6f2629b562c4b11338bde29381eccccc9
MD5 d419cbc9c3e74c6c4deeec184d1c6ba1
BLAKE2b-256 72b1c53f4996d8605ed5fadbfebd69058d0bfadc095ec3fce49115eb06e0e5d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page