Python client for the Fragment API
Project description
Fragment API Python
Professional Python library for Fragment.com API with async and sync support. Send Telegram Stars, Premium, and TON with automatic wallet validation.
Features
- ✅ Async & Sync interfaces
- ✅ 3 payment methods (Stars, Premium, TON)
- ✅ Automatic wallet balance validation
- ✅ WalletV4R2 support
- ✅ Comprehensive error handling
- ✅ Type hints & logging
Installation
pip install fragment-api-py
Quick Start
Synchronous
from FragmentAPI import SyncFragmentAPI
api = SyncFragmentAPI(
cookies="your_cookies",
hash_value="your_hash",
wallet_mnemonic="your mnemonic...",
wallet_api_key="your_api_key"
)
result = api.buy_stars('username', 100)
if result.success:
print(f"TX: {result.transaction_hash}")
else:
print(f"Error: {result.error}")
api.close()
Asynchronous
import asyncio
from FragmentAPI import AsyncFragmentAPI
async def main():
api = AsyncFragmentAPI(
cookies="your_cookies",
hash_value="your_hash",
wallet_mnemonic="your mnemonic...",
wallet_api_key="your_api_key"
)
result = await api.buy_stars('username', 100)
if result.success:
print(f"TX: {result.transaction_hash}")
await api.close()
asyncio.run(main())
Methods
buy_stars(username, quantity)
Send Telegram Stars to user
username(str): Target usernamequantity(int): Number of stars (1-999999)
gift_premium(username, months)
Gift Premium subscription (3, 6, or 12 months)
username(str): Target usernamemonths(int): Duration in months
topup_ton(username, amount)
Top up Telegram Ads account with TON
username(str): Target usernameamount(int): Amount of TON (1-999999)
get_wallet_balance()
Get current wallet balance and address
Setup
1. Get Fragment Cookies
- Open fragment.com in browser
- Press F12 → Application → Cookies
- Copy cookies:
stel_ssid,stel_token,stel_dt,stel_ton_token - Combine:
stel_ssid=value; stel_token=value; ...
2. Get Hash Value
From DevTools Network tab → fragment.com/api requests → copy hash parameter
3. Setup TON Wallet
- Get 24-word seed phrase from TON wallet (Tonkeeper, MyTonWallet, etc)
- Fund wallet with TON for transactions
4. Get API Key
- Go to https://tonconsole.com
- Create project
- Generate API key from Settings
Exceptions
AuthenticationError- Invalid cookies/hashUserNotFoundError- User doesn't existInvalidAmountError- Invalid quantity/amountInsufficientBalanceError- Low wallet balanceTransactionError- TX execution failedNetworkError- Network request failedWalletError- Wallet operation failedPaymentInitiationError- Fragment API error
Error Handling
from FragmentAPI import InsufficientBalanceError, UserNotFoundError
try:
result = api.buy_stars('username', 100)
if not result.success:
print(f"Error: {result.error}")
except InsufficientBalanceError as e:
print(f"Low balance: {e}")
except UserNotFoundError as e:
print(f"User not found: {e}")
finally:
api.close()
Security
Store credentials in environment variables:
import os
api = SyncFragmentAPI(
cookies=os.getenv('FRAGMENT_COOKIES'),
hash_value=os.getenv('FRAGMENT_HASH'),
wallet_mnemonic=os.getenv('WALLET_MNEMONIC'),
wallet_api_key=os.getenv('WALLET_API_KEY')
)
Requirements
- Python 3.7+
- requests >= 2.28.0
- aiohttp >= 3.8.0
- tonutils >= 0.3.0
- pytoniq-core >= 0.1.0
Documentation
Full documentation: https://github.com/S1qwy/fragment-api-py
License
MIT License
Support
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
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-3.0.2.tar.gz.
File metadata
- Download URL: fragment_api_py-3.0.2.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f939b929a5f0771a44bb69f780bfeec15e7c01637211944367e2fa1ebed221df
|
|
| MD5 |
163d8c2ebc82a7d6027cd96e775b4051
|
|
| BLAKE2b-256 |
049dd82d9ab8e5ec3908574b9f46c106cc3cb43bf6f9433e46fecf62e6433ed9
|
File details
Details for the file fragment_api_py-3.0.2-py3-none-any.whl.
File metadata
- Download URL: fragment_api_py-3.0.2-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b60daef694a873b142d44fcebfcf6f06c3a449e08f66a90746ada5e0a2de875
|
|
| MD5 |
54d54e4b4cb8177671f217ccdd42ea68
|
|
| BLAKE2b-256 |
2d03ec78627652f479e0449431aeb1a891e64a95c87d4bdc2facae6fd491850e
|