Fragment API Python SDK
Async Python library for Fragment.com automation
v12.1.0 — Gift Filters & Attributes | No-KYC Mode | Pydantic V2 | Selectolax Parser | Session Storage | Full Marketplace
Features
- Async-first — Full async/await support with
FragmentClient. - Two Modes — KYC-required mode with cookies + wallet, or No-KYC mode via MarketApp API.
- 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 or via MarketApp.
- 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+
- For KYC mode: 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 - For No-KYC mode: MarketApp API token + TON wallet seed phrase (12/18/24 words) + Tonconsole or Toncenter API key
Get a free API key at tonconsole.com.
Quick Start
KYC Mode (with Fragment.com cookies)
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())
No-KYC Mode (via MarketApp API)
import asyncio
from FragmentAPI import FragmentClient
async def main():
async with FragmentClient(
marketapp_token="your_marketapp_token",
seed="word1 word2 ... word24",
api_key="AF...",
wallet_version="V5R1",
) as client:
# Purchase Stars without KYC
result = await client.purchase_stars("durov", 100)
print(f"Purchase: {result}")
# Purchase Premium without KYC
result = await client.purchase_premium("durov", 3)
print(f"Purchase: {result}")
# Run a giveaway without KYC
result = await client.giveaway_stars(
channel="@my_channel",
amount=1000,
winners=10,
duration_days=7
)
print(f"Giveaway: {result}")
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_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 |
get_gift_filters() |
Get collections and their attributes (Model, Backdrop, etc.) |
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 |
MarketAppAPIError |
MarketApp API request failed |
UnexpectedError |
Unexpected internal error |
Operating Modes
KYC Mode (Traditional)
- Requires Fragment.com cookies
- Requires TON wallet with sufficient balance
- Full access to all Fragment.com features
- KYC verification required for some operations
No-KYC Mode (New in v12.0.0)
- Requires MarketApp API token (get at marketapp.io)
- Requires TON wallet with sufficient balance
- Supports purchases, giveaways, and price lookups
- No KYC verification needed
- Limited compared to full Fragment API
Choose the mode by providing either cookies (KYC mode) or marketapp_token (No-KYC mode) when initializing FragmentClient.
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-12.1.0.tar.gz.
File metadata
- Download URL: fragment_api_py-12.1.0.tar.gz
- Upload date:
- Size: 67.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
python-requests/2.34.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99eecba67d85f8952172fdd34fe1c5742ea0f559f7a20647bda005c815e909dc
|
|
| MD5 |
1356d746f463c5ea23e17a1c511abc63
|
|
| BLAKE2b-256 |
d68ff8e22dfe2de6d5680c7344694fe09b1eaa4fda59454fc0a329030f371794
|
File details
Details for the file fragment_api_py-12.1.0-py3-none-any.whl.
File metadata
- Download URL: fragment_api_py-12.1.0-py3-none-any.whl
- Upload date:
- Size: 79.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
python-requests/2.34.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2ef8cf69b5105f66cc76e74642d31cf5861dfb5b47dd23cfdf416d704bbef3d
|
|
| MD5 |
e10cba2eb74fbee39efe2c4c8dccc8e4
|
|
| BLAKE2b-256 |
568660a63a2bbd8c14385235b6797e5df0285114bb52f5fe37f083bdb3315c03
|