Skip to main content

Python library for the Fragment.com API — purchase Telegram Stars, Premium, and top up TON Ads balance.

Project description

Fragment Logo

Fragment API

Python library for the Fragment.com API — purchase Telegram Stars, Premium, and top up TON Ads balance.

PyPI version PyPI downloads Python License Stars CI

Report Bug · Request Feature · Donate TON

Disclaimer: This project is not affiliated with, endorsed by, or in any way officially connected with Fragment or Telegram.


✨ Features

  • 💰 TON Advertisement Topups — Top up Telegram Ads balance (1–1,000,000,000 TON)
  • 👑 Telegram Premium — Purchase Premium for any user (3, 6, or 12 months)
  • Telegram Stars Purchases — Purchase Stars for any Telegram user (50–1,000,000 Stars)
  • 🔐 Multi-wallet support — V4R2 and V5R1 wallet contract versions
  • Async-first — Built on httpx and asyncio

📦 Installation

pip install pyfragment

Requires Python 3.12+.


🚀 Quick Start

import asyncio
from pyfragment import FragmentClient

async def main():
    async with FragmentClient(
        seed="word1 word2 ... word24",
        api_key="YOUR_TONAPI_KEY",
        cookies={
            "stel_ssid": "...",
            "stel_dt": "...",
            "stel_token": "...",
            "stel_ton_token": "...",
        },
    ) as client:
        # Purchase 6 months of Telegram Premium
        result = await client.purchase_premium("@username", months=6)
        print(result.transaction_id)

        # Purchase 500 Stars
        result = await client.purchase_stars("@username", amount=500)
        print(result.transaction_id)

        # Top up 10 TON to Ads balance
        result = await client.topup_ton("@username", amount=10)
        print(result.transaction_id)

asyncio.run(main())

See the examples/ folder for ready-to-run scripts.


🔧 Configuration

FragmentClient parameters

Parameter Type Required Default Description
seed str 24-word TON wallet mnemonic phrase
api_key str Tonapi key from tonconsole.com
cookies dict | str Fragment session cookies (dict or JSON string)
wallet_version str "V5R1" Wallet contract version: "V4R2" or "V5R1"

Methods

Usernames can be passed with or without @.

Method Returns Description Limits
purchase_premium(username, months, show_sender=True) PremiumResult Purchase Telegram Premium months: 3, 6, or 12
purchase_stars(username, amount, show_sender=True) StarsResult Purchase Telegram Stars amount: 50–1,000,000
topup_ton(username, amount, show_sender=True) AdsTopupResult Top up Telegram Ads balance amount: 1–1,000,000,000
get_wallet() WalletInfo Get wallet address, state, balance

⚙️ Getting Required Credentials

🍪 Fragment.com Cookies

Prerequisites: Log in to fragment.com, connect your TON wallet.

  1. Install Cookie Editor
  2. Open fragment.com while logged in
  3. Click the extension → ExportHeader String
  4. Extract these four fields:
{
  "stel_ssid": "...",
  "stel_dt": "...",
  "stel_token": "...",
  "stel_ton_token": "..."
}

⚠️ Cookies expire. Refresh them if you start getting FragmentPageError or auth errors.

🔑 Tonapi Key

  1. Go to tonconsole.com
  2. Register and generate a new API key
  3. Pass it as api_key to FragmentClient

🌱 Wallet Seed Phrase

If you don't have a TON wallet, create one in Tonkeeper.
Go to Settings → Backup → copy the 24 words.

⚠️ Never share your seed phrase. Store it offline.

🔐 Wallet Version

Version Use when
V5R1 Default — Tonkeeper / MyTonWallet (wallets created after 2024)
V4R2 Older Tonkeeper or hardware wallets

🗂️ Error Handling

All exceptions inherit from FragmentError — see pyfragment/types/exceptions.py for the full list.

from pyfragment import FragmentClient, UserNotFoundError, ConfigurationError, WalletError

try:
    result = await client.purchase_stars("@unknown", amount=100)
except UserNotFoundError:
    print("User not found on Fragment")
except WalletError as e:
    print(f"Wallet issue: {e}")
except ConfigurationError as e:
    print(f"Bad params: {e}")

Made with ❤️ by @bohd4nx

Star ⭐ this repo if you found it useful!

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

pyfragment-2026.0.1.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

pyfragment-2026.0.1-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file pyfragment-2026.0.1.tar.gz.

File metadata

  • Download URL: pyfragment-2026.0.1.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for pyfragment-2026.0.1.tar.gz
Algorithm Hash digest
SHA256 b606382d328ea372cafdad599bb6094744920edcb97dc6fb769315f9c2db1e8c
MD5 0f536321b4a667c36010cc94e02a84c5
BLAKE2b-256 2058ecad776994a70634b82de67b727607de232b752c9d73c1f3fa16fd40aa00

See more details on using hashes here.

File details

Details for the file pyfragment-2026.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyfragment-2026.0.1-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for pyfragment-2026.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 358f62712d8901565907269f1ac0df7ed6b1c01306cdfae9781f7d62858f7a89
MD5 8a45bc2677931688e21f7e466d1ccf6b
BLAKE2b-256 6e19fb6879d6b8f2496b3c67b9f53aff92d286ba96641345ee02fdc5be866e75

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