Skip to main content

Python SDK for Fragment API - Buy Telegram Stars and Premium

Project description

Fragment Stars API

PyPI version Python versions License

Python SDK for purchasing Telegram Stars and Premium via Fragment.com

Buy Telegram Stars and Premium subscriptions programmatically using TON blockchain. Simple API, automatic transaction signing, queue management for Stars.

🇷🇺 Русская версия

Features

  • Buy Telegram Stars — gift stars to any Telegram user
  • 💎 Buy Telegram Premium — 3, 6, or 12 month subscriptions
  • 🔐 Two modes — with or without KYC (different commission rates)
  • Automatic transactions — just provide seed phrase, SDK handles the rest
  • 📊 Queue management — Stars purchases are queued and polled automatically
  • 🛡️ Type hints — full typing support for IDE autocompletion

Installation

pip install fragment-stars-api

Quick Start

from fragment_api import FragmentAPIClient

# Initialize with your API server
client = FragmentAPIClient("https://your-api-server.com:8443")

# Buy 50 stars for user
result = client.buy_stars("username", 50, seed="your_seed_base64")

if result.success:
    print(f"✅ Sent {result.amount} stars!")
    print(f"💰 Cost: {result.cost_ton} TON")
else:
    print(f"❌ Error: {result.error}")

Usage Examples

Buy Stars (No KYC)

Uses owner's Fragment account. Higher commission, but no user cookies needed.

from fragment_api import FragmentAPIClient

client = FragmentAPIClient("https://your-api-server.com:8443")

result = client.buy_stars(
    username="telegram_user",
    amount=100,
    seed="your_wallet_seed_base64"
)

print(f"Success: {result.success}")
print(f"Transaction ID: {result.transaction_id}")

Buy Stars (With KYC)

Uses user's Fragment cookies. Lower commission rate.

result = client.buy_stars(
    username="telegram_user",
    amount=100,
    seed="wallet_seed_base64",
    cookies="user_fragment_cookies_base64"
)

Buy Premium

Premium purchases are processed immediately by the API and return the final result directly.

# 3 months
result = client.buy_premium("username", 3, seed="...")

# 6 months
result = client.buy_premium("username", 6, seed="...")

# 12 months
result = client.buy_premium("username", 12, seed="...")

Check Commission Rates

rates = client.get_rates()

print(f"No KYC rate: {rates.rate_no_kyc}%")
print(f"With KYC rate: {rates.rate_with_kyc}%")

Check Queue Status

status = client.get_queue_status()

print(f"Queue length: {status['queue_length']}")
print(f"Estimated wait: {status['estimated_wait_seconds']}s")

Check Premium Eligibility

result = client.check_premium_eligibility("username")

if result['eligible']:
    print("✅ User can purchase Premium")
else:
    print(f"❌ Not eligible: {result.get('reason', 'Unknown reason')}")

Async Mode (Don't Wait)

# Returns immediately with request_id
response = client.buy_stars("user", 50, seed="...", wait=False)
print(f"Request ID: {response.request_id}")
print(f"Position in queue: {response.position}")

# Check status later
status = client.get_status(response.request_id)
print(f"Status: {status.status}")

API Reference

FragmentAPIClient

FragmentAPIClient(
    base_url: str,              # Required - your API server URL
    timeout: float = 30.0,
    poll_timeout: float = 300.0
)

Methods

Method Description
buy_stars(username, amount, seed, cookies?, local_storage?, wait?) Buy Telegram Stars through the queue
buy_premium(username, duration, seed, cookies?, local_storage?, wait?) Buy Telegram Premium directly
get_rates() Get commission rates
get_queue_status() Get queue status and statistics
check_premium_eligibility(username) Check if user is eligible for Premium
get_status(request_id) Get request status

Exceptions

from fragment_api import FragmentAPIError, QueueTimeoutError

try:
    result = client.buy_stars("user", 50, seed="...")
except QueueTimeoutError:
    print("Request timed out")
except FragmentAPIError as e:
    print(f"Error [{e.error_code}]: {e.message}")

How It Works

  1. For Stars, you call buy_stars() and the API adds the request to the queue
  2. The SDK polls GET /api/v1/queue/:request_id until the Stars purchase is completed or failed
  3. For Premium, you call buy_premium() and the API returns the final purchase result directly
  4. Server opens Fragment.com in headless browser
  5. Server signs TON transaction with your seed phrase
  6. Stars/Premium delivered to recipient's Telegram

Requirements

  • Python 3.9+
  • TON wallet with sufficient balance
  • Wallet seed phrase (24 words, base64 encoded)

How to encode seed phrase

echo -n "word1 word2 word3 ... word24" | base64

How to get Fragment cookies (for KYC mode)

KYC mode requires your Fragment.com cookies for lower commission rates.

📖 See detailed Cookie Guide for step-by-step instructions with screenshots and troubleshooting.

Quick Guide

Required cookies:

  • stel_token - Session authentication token
  • stel_ssid - Session ID
  • stel_ton_token - TON wallet connection token (CRITICAL - required for purchases)
  • stel_dt - Timezone offset

Steps:

  1. Login to Fragment: Go to https://fragment.com and login via Telegram
  2. Connect TON Wallet: Click "Connect Wallet" and connect Tonkeeper/MyTonWallet
  3. Open DevTools: Press F12 → Application → Cookies → https://fragment.com
  4. Copy cookie values: Copy the Value field for each required cookie
  5. Create JSON:
    {
        "stel_token": "your_value",
        "stel_ssid": "your_value",
        "stel_ton_token": "your_value",
        "stel_dt": "-180"
    }
    
  6. Encode to base64:
    cat cookies.json | base64 -w 0
    
  7. Use in code:
    result = client.buy_stars(
        username="user",
        amount=50,
        seed="your_seed_base64",
        cookies="your_cookies_base64"
    )
    

⚠️ Important: The stel_ton_token cookie is required for purchases. Make sure your TON wallet is connected on fragment.com before extracting cookies!

💡 Tip: If you don't want to deal with cookies, use No-KYC mode (just omit the cookies parameter). It has higher commission but no cookies needed.

Author

Basebay — Backend developer focused on automation, bots, and infrastructure tools.

Support

License

MIT License - see LICENSE file.

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

fragment_stars_api-2.0.2.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

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

fragment_stars_api-2.0.2-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file fragment_stars_api-2.0.2.tar.gz.

File metadata

  • Download URL: fragment_stars_api-2.0.2.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for fragment_stars_api-2.0.2.tar.gz
Algorithm Hash digest
SHA256 58d95c2481e8dd8ccc6d68cd68d3528fbcef5bb7cf6e51e3984a7ee2364e4682
MD5 1b7efde1f0e7213adca14964391691b1
BLAKE2b-256 8373327a237012b623047de7a182fb3c1e98b65f7c59d95965975a41e0bf7cf2

See more details on using hashes here.

File details

Details for the file fragment_stars_api-2.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fragment_stars_api-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 29db1a7818a0a92e75c22534b9cfa93f1f944eb4012cd9e5bbf4235d73ae7557
MD5 e5ce6b05a4afd119e6f841eb2b496783
BLAKE2b-256 813d923e3ebd1d4eb04d9cccc4c99409c059f5d346dc2e0a381119e40d3442e6

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