Fragment API Python
One async client. Explicit payment states. A complete Fragment workspace.
Stars · Premium · Gifts · Usernames · Numbers · Ads · Gateway
Read the documentation / Explore examples / Report an issue
Built for explicit workflows
fragment-api-py is an unofficial asynchronous Python SDK for Fragment.com.
Browse the marketplace, resolve recipients, prepare transactions for external signing, or configure a payer wallet for automatic broadcasting. Work with typed results instead of treating every accepted request as a completed purchase.
Gram Earnings top-ups removed
Fragment removed Telegram account balance top-ups. The SDK removes purchase("ton", ...), Gram top-up batch items, and get_ads_topup_recipient(). Stars, Premium, Ads account recharge and Gateway retain their own workflows. Past top-up records remain available through get_topup_history().
BNB Smart Chain payments
Use payment_method="usdt_bsc" to create an external USDT invoice on BNB Smart Chain. The invoice exposes the raw amount and token precision for payment from an external wallet.
Revenue withdrawal links
Revenue withdrawal links now have a three-stage API for /stars/withdraw and /ads/withdraw:
info = await client.inspect_withdrawal(url) # GET only
request = await client.prepare_withdrawal(url) # server initialization, state-changing
# Review request.destination and request.confirm_message in your application.
if request.confirmation_required:
result = await client.confirm_withdrawal(request) # explicit submission
WithdrawalInfo includes the link kind, mode, destination and optional amount/currency/source fields when exposed as form values. Missing metadata is None; units are never inferred. kyc_required=None means the page did not state a requirement, not that KYC is unnecessary. prepare_withdrawal() can still raise KycRequiredError based on the server response.
Preparation calls the server's initialization endpoint. Fragment can return a result without a confirmation challenge, so preparation must be treated as state-changing. Inspect request.server_response and do not automatically repeat it. Confirmation requires the returned challenge and the original destination account. A challenge is submitted at most once per client instance, including after a network error; this guard is not a durable cross-process journal. After an uncertain result, inspect the original withdrawal in Telegram/Fragment before retrying.
Use the same user-owned cookies throughout. Configure a payer seed or sender_account to select the withdrawal destination; a blockchain API key is not needed for these HTTP calls. This flow does not sign a TON payment or obtain withdrawal links from Telegram. Generate a valid link in Telegram first. Real reward withdrawals were not performed during development.
Link tokens, opaque state and confirmation hashes are hidden from model repr, but serialization still contains them: keep exported requests private. Invalid hosts/routes, duplicate or empty transaction parameters and expired/mismatched link state are rejected. NFT withdrawal links retain their existing separate methods.
Upgrading
See the migration guide for breaking changes and previous API transitions.
Choose your workflow
| Workflow | Configuration | Result |
|---|---|---|
| Account browsing | Your Fragment cookies | Marketplace and user-owned account data |
| External TON signing | Your cookies and a complete sender account or offline-derived payer account | PreparedTransaction |
| Automatic TON payment | Your cookies, payer seed and blockchain API key | Broadcast receipt with explicit confirmation state |
| EVM payment | Your cookies and a supported EVM payment method | An invoice for external payment |
All Fragment HTTP operations require a user-owned cookie session. Native automatic payments additionally require a wallet-connected session.
Constructing a client without cookies is supported for offline validation and wallet utilities. It does not trigger authentication. Explicit login and cookie refresh use only the seed supplied by the caller.
Installation
Python 3.10 or newer
Install from GitHub using a pinned release commit. This is the recommended source.
python -m pip install "fragment-api-py @ git+https://github.com/S1qwy/fragment-api-py.git@v14.5.0"
With uv:
uv add "fragment-api-py @ git+https://github.com/S1qwy/fragment-api-py.git@v14.5.0"
PyPI is also available. Pin the known release with python -m pip install "fragment-api-py==14.5.0".
Optional integrations:
| Extra | Name |
|---|---|
| Redis storage | redis |
| Terminal QR rendering | qr |
| Development tools | dev |
To install an extra, replace fragment-api-py before @ with its extras form, such as fragment-api-py[redis].
Automatic TON payments require a valid mnemonic and a provider key from Tonconsole or Toncenter.
Start with an example
The repository keeps executable examples in one place rather than duplicating code throughout the documentation.
| Your goal | Start here |
|---|---|
| Configure the client | Basic setup |
| Authenticate a full account | Authentication |
| Buy Stars or Premium | Stars · Premium |
| Prepare an external payment | External signing |
| Search gifts and attributes | Marketplace search |
| Handle payment outcomes | Error handling |
Browse the complete example guide
Batches, fees, and recovery
purchase(items) prepares all invoices and submits their combined messages
in one wallet transaction. A batch that exceeds wallet capacity is rejected
before broadcasting; it is never silently split. In preparation mode,
result.transaction contains the combined payload for external signing.
Native TON purchases include a separate 1.5% service fee
(FEE_BASIS_POINTS = 150), sent to FEE_ADDRESS in
FragmentAPI/types/constants.py. This is additional to network fees and separate
from voluntary support. Inspect payment_nanoton, fee_nanoton,
gas_reserve_nanoton, and required_nanoton before signing. The percentage fee
does not apply to USDT or external EVM payments.
Automatic payments durably record the signed BOC before broadcast. Use
list_payments(), get_payment(operation_id), and
reconcile_payment(operation_id) to recover after cancellation or restart
without repeating a blockchain payment. The default journal and wallet locks
are stored under ~/.fragment-api; deployments must preserve that directory.
See payment batches and recovery for result semantics, confirmation limits, operator resolution, and coordination across processes/hosts.
Payment networks
| Method | Network | Asset | SDK behavior |
|---|---|---|---|
ton |
TON | TON | Prepare or broadcast |
usdt_ton |
TON | USDT | Prepare or broadcast |
usdt_tron |
TRON | USDT | External invoice |
usdt_eth |
Ethereum | USDT | External invoice |
usdt_pol |
Polygon | USDT | External invoice |
usdt_bsc |
BNB Smart Chain | USDT | External invoice |
usdc_eth |
Ethereum | USDC | External invoice |
usdc_base |
Base | USDC | External invoice |
usdc_pol |
Polygon | USDC | External invoice |
Availability is subject to Fragment's response and operation-specific restrictions. Ads and Gateway recharge flows use native TON.
Know what happened
| State | Meaning |
|---|---|
| Prepared | An unsigned transaction exists; nothing has been broadcast |
| Broadcast | The wallet call returned; fulfillment has not necessarily completed |
| Confirmed | The purchase flow observed Fragment's completion signal |
| Unknown | The broadcast outcome could not be established; reconciliation is required |
Documentation
|
Integration Client and authentication |
Marketplace and operations Marketplace and search |
Operational notes
- Reuse a client and close it with an asynchronous context manager or
aclose(). - Keep payer credentials, session cookies, and login codes out of source control and logs.
- Use your own sender account for external signing.
- Local clients/processes sharing a payer use OS wallet locks and a durable journal. Multi-host deployments must configure shared payment storage and distributed locks.
- Fragment HTML and private endpoints can change independently of this package.
- This project is not affiliated with or endorsed by Fragment, Telegram, or TON.
Support the project
Development, maintenance, and issue reports are welcome.
TON address
UQAcsdD09x9dzj7Jc-MznN-SLUxPPMmwKQxsC2Ax_F03TBAH
Metadata
Release files for fragment-api-py 14.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fragment_api_py-14.5.0.tar.gz | 79.9 kB | With provenance | Details for fragment_api_py-14.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fragment_api_py-14.5.0-py3-none-any.whl | Python 3 | none | any | Details for fragment_api_py-14.5.0-py3-none-any.whl |
Total release size: 178.0 kB
Release files / fragment_api_py-14.5.0.tar.gz
| Download URL | fragment_api_py-14.5.0.tar.gz |
|---|---|
| Size | 79.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
746ce816060be1402232f101ab9dff4804177ce03da917329bb08087e9651a18
|
|
BLAKE2b-256 checksum How to use checksums |
2ad56940bcfabe399ebdc184c251aa33fd71e1d84a789f97814e8558d55dd0a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / fragment_api_py-14.5.0-py3-none-any.whl
| Download URL | fragment_api_py-14.5.0-py3-none-any.whl |
|---|---|
| Size | 98.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
408b076fe37d43da663883854455e79b3fc68ed0ee8c0eefc3bc0d653cbbfd9a
|
|
BLAKE2b-256 checksum How to use checksums |
5a76f78adea0747aa807936bd8b8c3a09db79327adebbe87d08987f3ecb5eeb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logSecurity for fragment-api-py 14.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for fragment_api_py-14.5.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.