Skip to main content

fragment-api-dev

PyPI Python License API SDK

The focused Python SDK for buying Telegram Stars and Telegram Premium through Fragment.

  • GRAM and USDT on TON
  • No API key
  • Automatic status polling
  • Zero runtime dependencies
  • Pre-payment recipient checks without wallet credentials

Install

pip install fragment-api-dev

Quick start

This example uses a 12-word wallet at account index 0. If you use a 24-word TON mnemonic or a Base64 32-byte private key, remove account_index.

import os

from fragment_api import FragmentAPI


api = FragmentAPI()

check = api.check_stars_availability("@telegram_user", 50, "gram")
if not check.available:
    raise SystemExit(f"{check.message} {check.action or ''}")

# Accept customer payment only after the check succeeds.
purchase = api.buy_stars(
    username="@telegram_user",
    amount=50,
    payment_method="gram",
    seed=os.environ["TON_WALLET_SEED"],
    account_index=0,  # Required for a 12-word seed
)

result = api.wait(purchase.purchase_id)

if result.completed:
    print("Delivered:", result.transaction_hash)
else:
    print("Not completed:", result.status, result.error)

The SDK checks the recipient, generates an idempotency key, submits the purchase, and provides a typed Purchase result.

Use check_premium_availability("@telegram_user", 3, "usdt") for Premium. These checks never need or accept a seed, wallet address, account index, or API key.

Run the check shortly before payment. It is not a reservation or guarantee. If the API returns 429, wait for error.retry_after; on 503, retry later and do not charge yet.

12-word wallets

A 12-word wallet can contain many TON accounts. Tell the API which account pays:

What you know Send What happens
Seed + wallet address seed, wallet_address The API finds the index
Seed + account index seed, account_index The API uses V5R1 at that index
Seed + address + index all three The API verifies and uses that exact wallet

A 12-word seed alone is not enough. Send wallet_address or account_index.

wallet = api.resolve_wallet(
    seed=os.environ["TON_WALLET_SEED"],
    wallet_address=os.environ["TON_WALLET_ADDRESS"],
)

purchase = api.buy_stars(
    username="@telegram_user",
    amount=50,
    payment_method="gram",
    seed=os.environ["TON_WALLET_SEED"],
    account_index=wallet.account_index,
)

If you already know the index, skip resolve_wallet() and pass account_index=0 (or your actual index). You may also pass wallet_address="UQ..." directly. The API searches indices 0..20 during a purchase and 0..100 through resolve_wallet().

For a 24-word TON mnemonic or Base64 32-byte private key, omit both wallet selectors.

Wallet selection errors

FragmentAPIError exposes code and action so your app can show the correct next step.

Code Client action
WALLET_SELECTION_REQUIRED Add wallet_address or account_index
INVALID_BIP39_SEED Check all 12 words and their order
INVALID_WALLET_ADDRESS Send a valid TON friendly or raw address
INVALID_ACCOUNT_INDEX Send an integer from 0 to 100
WALLET_ADDRESS_MISMATCH Remove the index to search, or correct it
WALLET_INDEX_NOT_FOUND Call the resolver, then use its returned index
WALLET_RESOLVER_BUSY Wait briefly and retry the same resolve request

Prices

Get the 50-Stars reference price and Premium prices for 3, 6, and 12 months before showing a price to your customer:

catalog = api.get_prices()
print(catalog.stars.amount, catalog.stars.prices.gram, catalog.stars.prices.usdt)

quote = api.get_stars_price(100)
print(quote.prices.gram, quote.prices.usdt)

Use get_premium_price(3), get_premium_price(6), or get_premium_price(12) for Premium. Price values are strings to preserve their exact decimal value. A quote can have stale=True when the latest available quote is being served.

Telegram Premium

purchase = api.buy_premium(
    username="@telegram_user",
    months=3,
    payment_method="usdt",
    seed=os.environ["TON_WALLET_SEED"],
    account_index=0,  # Required for a 12-word seed
)

result = api.wait(purchase.purchase_id)

Premium durations are 3, 6, or 12 months.

Payments

Value Payment
gram GRAM on TON
usdt USDT on TON

USDT purchases require a small GRAM balance for the network fee.

Public API

Method Purpose
buy_stars() Buy 50 or more Telegram Stars
buy_premium() Buy Telegram Premium
create_purchase() Create a purchase with explicit product fields
get_purchase() Read the latest purchase state
get_prices() Read the 50-Stars reference and Premium price catalog
get_price() Read a Stars or Premium quote
get_stars_price() Read a Stars quote for 50 to 1,000,000 Stars
get_premium_price() Read a quote for 3, 6, or 12 months of Premium
resolve_wallet() Find the account index for a 12-word wallet
check_availability() Check a recipient with explicit product fields
check_stars_availability() Check a Stars recipient before payment
check_premium_availability() Check a Premium recipient before payment
wait() Poll until the purchase reaches a terminal state

No authentication token or API key is required.

Metadata

Release files for fragment-api-dev 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fragment-api-dev 1.3.0
File Size Uploaded
fragment_api_dev-1.3.0.tar.gz 16.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fragment-api-dev 1.3.0
File Interpreter ABI Platform
fragment_api_dev-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.7 kB

Release files / fragment_api_dev-1.3.0.tar.gz

Download URL fragment_api_dev-1.3.0.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
aa9371d08c6d5c99b2e957d86abcc282ff95804df89656fc532343751629a6ce
BLAKE2b-256 checksum
How to use checksums
e90550c38910717de877d79e5c97fbe4be9928ba024bddcb140034178a742dac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / fragment_api_dev-1.3.0-py3-none-any.whl

Download URL fragment_api_dev-1.3.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0cd4b95cca2d451d2f884b0766e5bc60a8da875858a9657437956d5754fea645
BLAKE2b-256 checksum
How to use checksums
b4fea7a639e75719760f613eaa38b314150c5c7a5021142b621f53a4047f0068
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release history Release notifications | RSS feed

1.4.0

2 release files

This release

1.3.0 This release

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page