Skip to main content

Async Python client for the Fragment API. Buy Stars and Premium, top up TON and Ads balances, run giveaways, manage anonymous numbers, and search Fragment listings.

Project description

Fragment Logo

Fragment API

Async Python client for the Fragment API. Buy Stars and Premium, top up TON and Ads balances, run giveaways, manage anonymous numbers, and search Fragment listings.

PyPI version PyPI Downloads Python Tests License

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.


Installation

pip install pyfragment

To install the latest unreleased changes from the dev branch:

pip install git+https://github.com/bohd4nx/pyfragment.git@dev

Requires Python 3.10+.


Configuration

Parameter Type Default Description
seed str 24-word TON wallet mnemonic
api_key str Tonapi key from tonconsole.com
cookies dict | str Fragment session cookies
wallet_version str "V5R1" "V4R2" or "V5R1"
timeout float 30.0 HTTP request timeout in seconds

Credentials

Fragment cookies — log in to fragment.com and connect your TON wallet. You can get cookies in two ways:

  • Automatically (recommended) — use get_cookies_from_browser(), which reads them directly from your browser's on-disk store. No extension needed:
    from pyfragment.utils import get_cookies_from_browser
    result = get_cookies_from_browser("chrome")  # or "firefox", "edge", "brave", ...
    # result.cookies — dict[str, str] to pass to FragmentClient
    # result.expires — ISO 8601 expiry of stel_ssid, or None for session cookies
    
  • Manually — install Cookie Editor and export these four keys: stel_ssid, stel_dt, stel_token, stel_ton_token. Pass them as a dict or JSON string.

Refresh when you get authentication errors.

Tonapi key — generate at tonconsole.com.

Seed phrase — 24-word mnemonic from your TON wallet (Tonkeeper → Settings → Backup). Never share it.


Usage

import asyncio
from pyfragment import FragmentClient


async def main() -> None:
    async with FragmentClient(
        seed="word1 word2 ... word24",
        api_key="YOUR_TONAPI_KEY",
        cookies={
            "stel_ssid": "...",
            "stel_dt": "...",
            "stel_token": "...",
            "stel_ton_token": "...",
        },
    ) as client:
        wallet = await client.get_wallet()
        print(f"Wallet: {wallet.address} | TON: {wallet.ton_balance} | USDT: {wallet.usdt_balance}")

        recipient = "https://t.me/username"  # also supports: @username, username

        stars = await client.purchase_stars(recipient, amount=500, payment_method="usdt_ton")
        print(f"Stars sent: {stars.amount} to {stars.username} | tx: {stars.transaction_id}")

        premium = await client.purchase_premium(recipient, months=6, payment_method="ton")
        print(f"Premium sent: {premium.amount} months to {premium.username} | tx: {premium.transaction_id}")


asyncio.run(main())

Full runnable examples:

Payload debug/decode helper (thanks):


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.2.2.tar.gz (43.9 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.2.2-py3-none-any.whl (39.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyfragment-2026.2.2.tar.gz
  • Upload date:
  • Size: 43.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyfragment-2026.2.2.tar.gz
Algorithm Hash digest
SHA256 ce0c9f537b35b88cf9703e2a3fa53bbf2304547db75ffa8a17a194316d7b3e85
MD5 08471030e5dda618db63085c9e20502e
BLAKE2b-256 95447371495d1792260a8d72a9f89250841bc047dae0a2af8035beb2cc024be1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfragment-2026.2.2.tar.gz:

Publisher: publish.yml on bohd4nx/pyfragment

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: pyfragment-2026.2.2-py3-none-any.whl
  • Upload date:
  • Size: 39.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyfragment-2026.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 731ad00f0a040bc568479bfd5c93f93f4a01dfa0e561d5469b309c2aa4818dc4
MD5 7f9c01adf56c09590544676949d10fbb
BLAKE2b-256 124f30cf44bb00064376ffbc85809132379214291faa08e5fa6478d1d7624874

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfragment-2026.2.2-py3-none-any.whl:

Publisher: publish.yml on bohd4nx/pyfragment

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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