Skip to main content

Python SDK for TonWise — Trust & Safety API for the TON blockchain

Project description

TonWise Python SDK

PyPI Python License: MIT

Python SDK for TonWise — Trust & Safety API for the TON blockchain. Detect rug pulls, sybil clusters, contract spoofing, and drainer activity in 3 lines of code.

pip install tonwise

Quickstart

from tonwise import TonWiseClient

with TonWiseClient(api_key="tg_live_xxx") as client:
    result = client.scan("EQA1234567...")
    print(f"Safe: {result.is_safe}, Dump probability: {result.dump_probability}%")

Async usage

For AI agents, trading bots, and FastAPI / aiohttp services:

import asyncio
from tonwise import AsyncTonWiseClient

async def main():
    async with AsyncTonWiseClient(api_key="tg_live_xxx") as client:
        result = await client.scan("EQA1234567...")
        print(f"Safe: {result.is_safe}, Sybils: {result.sybil_clusters}")

asyncio.run(main())

Webhooks

Subscribe to real-time security events. Supported event types:

  • scam — confirmed scam contract
  • spoof — confusable / invisible-character token spoofing
  • dump_alert — high dump probability (>70%)
  • sybil_cluster — coordinated wallet activity
  • pump_warning — pump-and-dump pattern detected
  • manifest_forgery — fake jetton metadata
  • w5_batch_drain — drainer activity via W5 batch transfers
  • * — subscribe to all events
client.register_webhook(
    url="https://your-app.com/tonwise-callback",
    events=["scam", "dump_alert"],
)

# List your webhooks
hooks = client.list_webhooks()

# Disable a webhook
client.delete_webhook(webhook_id=42)

Verify HMAC-SHA256 signatures

Every webhook payload is signed with the secret returned at registration:

import hmac, hashlib

def verify_signature(secret: str, body: bytes, signature_header: str) -> bool:
    expected = hmac.new(secret.encode(), body, hashlib.sha256).hexdigest()
    received = signature_header.removeprefix("sha256=")
    return hmac.compare_digest(received, expected)

Error handling

The SDK raises typed exceptions so you can branch cleanly:

from tonwise import TonWiseClient, AuthError, RateLimitError, APIError

try:
    result = client.scan("EQA1234...")
except AuthError:
    # 401 — bad or revoked API key
    ...
except RateLimitError as e:
    # 429 — wait e.retry_after seconds and retry
    time.sleep(e.retry_after)
except APIError as e:
    # other 4xx / 5xx — inspect e.status_code and e.body
    ...

Features

  • Sync (requests) and async (aiohttp) clients — both first-class
  • Webhook management: register / list / delete
  • Type hints + Pydantic v2 response models
  • Rate-limit aware: RateLimitError.retry_after exposes the server's hint
  • Custom base_url for staging environments

Get an API key

Visit tonguard.app/pricing. The free tier gives 1 000 calls/day — no credit card required.

Tier Calls/day Webhooks Price
Free 1 000 1 $0
Pro 50 000 5 $99/month
Business 250 000 10 $499/month
Enterprise unlimited 10+ custom

Development

git clone https://github.com/tonwise/tonwise-python
cd tonwise-python
pip install -e ".[dev]"
pytest

License

MIT — see LICENSE.

Links

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

tonwise-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

tonwise-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file tonwise-0.1.0.tar.gz.

File metadata

  • Download URL: tonwise-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for tonwise-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e49635540b909a728c0e726b547ad422a4c54a233419321ba97286686aa513f0
MD5 d83f952bcb8968873d1785ca89196ec1
BLAKE2b-256 0a1ecd063cc0b6861d34fceefc973b747ece168f1a4c6ed47807fe54d8a736f0

See more details on using hashes here.

File details

Details for the file tonwise-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tonwise-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for tonwise-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4ccd33df94df5dcc7a69db3f34ba5e11f91aa2a349cd69dc625e43b4143a425
MD5 9da37bc2400c1de1cbf921f1cdea8fd0
BLAKE2b-256 848cdba767bf88ad54d2763951dab8e1360d9fe2e02f8e85c15685b767ebb752

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