Fragment API Python SDK
Async Python library for Fragment.com automation
v11.0.0 — Pydantic V2 | Selectolax Parser | Session Storage | Full Marketplace
What's New in v11.0.0
| Feature | Description |
|---|---|
| Pydantic V2 | Complete migration from dataclasses to Pydantic V2 models with full type validation. |
| Selectolax Parser | Replaced fragile regex parsing with fast CSS-selector based Selectolax (Lexbor backend). |
| Session Storage | Built-in cookie persistence with FileSessionStorage and RedisSessionStorage backends. |
| Gateway API | Full support for Telegram Gateway credit purchases and price queries. |
| Offers | Make offers on unlisted usernames, numbers, and gifts. |
| Cancel Auction | Cancel active auctions with no bids. |
| Subscribe/Unsubscribe | Get Telegram notifications for auction updates. |
| Ads Withdrawal | Withdraw Ads revenue to your wallet. |
| Batch Operations | Improved chunking (V4R2: 4, V5R1: 255 messages per transaction). |
| EVM Payments | USDT/USDC on Ethereum, Polygon, and BASE chains. |
Features
- Async-first — Full async/await support with
FragmentClient. - Pydantic Models — All API responses return strongly-typed Pydantic models.
- Selectolax Parsing — Robust CSS-selector based HTML parsing.
- Session Storage — Persist cookies in files or Redis.
- Purchases — Stars (50–10M), Premium (3/6/12 months), GRAM Ads top-up.
- Batch Operations — Multiple purchases in grouped on-chain transactions.
- EVM Payments — USDT/USDC on Ethereum, Polygon, and BASE chains.
- Giveaways — Stars and Premium giveaways for channels (up to 24K winners).
- Marketplace — Search/bid on usernames, numbers, and gifts.
- Auctions — Start auctions, set fixed prices, place bids, buy-now.
- Offers — Make offers on unlisted items.
- Gateway — Recharge Telegram Gateway credits.
- NFTs — Transfer gifts, withdraw to wallet.
- Wallet — V4R2 and V5R1 support via
tonutils. - Authentication — Auto-authenticate via TON wallet proof + Telegram OAuth.
- Anonymous Numbers — Login codes, toggle delivery, terminate sessions.
Installation
pip install fragment-api-py
Requirements:
- Python 3.10+
- Fragment cookies (
stel_ssid,stel_dt,stel_token;stel_ton_tokenfor wallet ops) - TON wallet seed phrase (12/18/24 words)
- Tonconsole or Toncenter API key
Get a free API key at tonconsole.com.
Quick Start
import asyncio
from FragmentAPI import FragmentClient
from FragmentAPI.types.results import EvmPaymentResult
async def main():
async with FragmentClient(
cookies={
"stel_ssid": "...",
"stel_token": "...",
"stel_dt": "...",
"stel_ton_token": "..."
},
seed="word1 word2 ... word24",
api_key="AF...",
wallet_version="V5R1",
) as client:
# Wallet info
wallet = await client.get_wallet()
print(f"Balance: {wallet.gram_balance} GRAM, {wallet.usdt_balance} USDT")
# Purchase Stars
result = await client.purchase_stars("durov", 100)
print(f"TX: {result.transaction_id}")
# Batch operations
batch = await client.batch_purchase([
{"type": "premium", "username": "durov", "months": 3},
{"type": "stars", "username": "telegram", "amount": 250},
])
print(f"Batch: {batch.succeeded}/{batch.total} succeeded")
# EVM payment
evm = await client.purchase_stars("durov", 50, payment_method="usdc_base")
if isinstance(evm, EvmPaymentResult):
inv = evm.invoice
print(f"Send {inv.invoice_amount} {inv.token_symbol} to {inv.invoice_address}")
asyncio.run(main())
Session Storage
Persist cookies across restarts:
from FragmentAPI import FragmentClient, FileSessionStorage, RedisSessionStorage
# File-based storage
storage = FileSessionStorage(directory=".fragment_sessions")
client = await FragmentClient.from_storage(
session_storage=storage,
session_id="my_session",
seed="word1 word2 ... word24",
api_key="AF...",
)
# Redis storage
storage = RedisSessionStorage(redis_url="redis://localhost:6379/0", ttl=3600)
client = await FragmentClient.from_storage(
session_storage=storage,
session_id="my_session",
seed="word1 word2 ... word24",
api_key="AF...",
)
Authentication
import asyncio
from FragmentAPI import FragmentClient
async def main():
# Auto-authenticate via TON wallet + Telegram
cookies = await FragmentClient.authenticate(
seed="word1 word2 ... word24",
wallet_version="V5R1",
phone="+71234567890", # Omit for QR code flow
)
async with FragmentClient(
cookies=cookies,
seed="word1 word2 ... word24",
api_key="AF...",
) as client:
profile = await client.get_profile()
print(f"Logged in as: {profile.name}")
asyncio.run(main())
Payment Methods
| Method | Chain | Token | Behavior |
|---|---|---|---|
gram / ton |
TON (Gram) | GRAM | Automatic on-chain TX |
usdt_gram / usdt_ton |
TON (Gram) | USDT | Automatic on-chain TX |
usdt_eth |
Ethereum | USDT | Returns invoice |
usdt_pol |
Polygon | USDT | Returns invoice |
usdc_eth |
Ethereum | USDC | Returns invoice |
usdc_base |
BASE | USDC | Returns invoice |
usdc_pol |
Polygon | USDC | Returns invoice |
API Overview
Purchases & Giveaways
| Method | Description |
|---|---|
purchase() |
Unified single/batch purchase |
purchase_stars() |
Send Stars to a user |
purchase_premium() |
Gift Premium to a user |
topup_gram() |
Top up GRAM to Ads balance |
topup_ton() |
Alias for topup_gram() |
batch_purchase() |
Batched multi-item purchases |
giveaway_stars() |
Stars giveaway for a channel |
giveaway_premium() |
Premium giveaway for a channel |
Marketplace
| Method | Description |
|---|---|
search_usernames() |
Search username listings |
search_numbers() |
Search anonymous numbers |
search_gifts() |
Search gift marketplace |
place_bid() |
Bid or buy-now on an item |
start_auction() |
Start an auction |
sell_asset() |
Sell at a fixed price |
make_offer() |
Make offer on unlisted item |
cancel_auction() |
Cancel active auction |
subscribe_to_item() |
Get auction notifications |
unsubscribe_from_item() |
Stop auction notifications |
Asset Info & History
| Method | Description |
|---|---|
get_username_info() |
Detailed username info |
get_number_info() |
Detailed number info |
get_gift_info() |
Detailed gift info |
get_stars_prices() |
Stars package prices |
get_stars_price() |
Price for specific Stars quantity |
get_premium_prices() |
Premium prices |
get_stars_history() |
Stars transaction history |
get_premium_history() |
Premium transaction history |
get_topup_history() |
Ads topup history |
Account & Assets
| Method | Description |
|---|---|
get_wallet() |
Wallet address & balances |
get_profile() |
Account profile info |
get_sessions() |
Active sessions |
terminate_session() |
Terminate a session |
get_my_assets() |
Owned assets |
get_my_bids() |
Bid history |
assign_to_telegram() |
Assign asset to account |
get_assign_accounts() |
Get available accounts |
NFTs & Withdrawals
| Method | Description |
|---|---|
search_nft_transfer_recipient() |
Find transfer recipient |
init_nft_transfer() |
Initialize NFT transfer |
transfer_nft() |
Execute NFT transfer |
init_nft_withdrawal() |
Withdraw NFT to wallet |
confirm_nft_withdrawal() |
Confirm NFT withdrawal |
init_stars_withdrawal() |
Withdraw Stars revenue |
confirm_stars_withdrawal() |
Confirm Stars withdrawal |
init_ads_withdrawal() |
Withdraw Ads revenue |
confirm_ads_withdrawal() |
Confirm Ads withdrawal |
Gateway
| Method | Description |
|---|---|
get_gateway_price() |
Get Gateway credits price |
recharge_gateway() |
Recharge Gateway credits |
Anonymous Numbers
| Method | Description |
|---|---|
get_login_code() |
Fetch pending login code |
toggle_login_codes() |
Enable/disable code delivery |
terminate_sessions() |
Terminate all sessions |
Low-Level
| Method | Description |
|---|---|
call() |
Send raw Fragment API request |
confirm_request() |
Confirm transaction after broadcast |
Exceptions
All exceptions inherit from FragmentError:
| Exception | Description |
|---|---|
ConfigurationError |
Invalid client configuration |
CookieError |
Missing or invalid cookies |
FragmentPageError |
Page loading or hash extraction failed |
UserNotFoundError |
Target user not found |
AlreadySubscribedError |
User already has Premium |
AnonymousNumberError |
Anonymous number operation failed |
TransactionError |
TON transaction failed |
ConfirmationTimeout |
Transaction not confirmed in time |
WalletError |
Balance insufficient or wallet issues |
VerificationError |
KYC verification required |
ParseError |
Failed to parse API response |
SessionStorageError |
Storage read/write failed |
UnexpectedError |
Unexpected internal error |
Support & License
Issues: GitHub Issues
Support the Project:
UQBsyxZvyQxDwAeOxoaWwO2HJoAmCKUoJlS_OpLzWHD9i2Xj
License: MIT — free for commercial and personal use.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fragment_api_py-11.0.0.tar.gz.
File metadata
- Download URL: fragment_api_py-11.0.0.tar.gz
- Upload date:
- Size: 59.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
python-requests/2.34.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b94dfda924fae01964f497b41c489a05777aeb332e45baab29ca9d8bb88183d
|
|
| MD5 |
7e373a84fc92a99c555f21fadb3ae016
|
|
| BLAKE2b-256 |
91861f3150585b7065ed5a2433649d2c56f4e1dfb471a9372f04adafb9e3698c
|
File details
Details for the file fragment_api_py-11.0.0-py3-none-any.whl.
File metadata
- Download URL: fragment_api_py-11.0.0-py3-none-any.whl
- Upload date:
- Size: 71.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
python-requests/2.34.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63aa9f63e7d60c18a402eb96fbd785fe3bbaa6e3008d00ba8026255e0e43d02f
|
|
| MD5 |
cec6a2eca6c082413a5ce9ec0f2e8e9e
|
|
| BLAKE2b-256 |
c03ac9f8af3e105c52bb92696b25239e285c92d36957e8d40a30990899e9d612
|