Skip to main content

Fragment

Fragment API Python

One async client. Explicit payment states. A complete Fragment workspace.

Stars · Premium · Gifts · Usernames · Numbers · Ads · Gateway

PyPI version Python 3.10 and newer Documentation MIT license

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.

Purchase

Telegram Stars, Premium gifts, channel giveaways, Ads top-ups, and Gateway credits.

Discover

Search usernames, collectible numbers, and gifts. Inspect attributes, prices, ownership, and auction history.

Manage

Operate user-owned assets, listings, offers, assignments, withdrawals, and sessions.

Release 14.2.0

USDT on TRON uses payment_method="usdt_tron" and returns ExternalPaymentResult with an ExternalInvoice. TRON payments are external: the SDK does not sign or broadcast TRC-20 transfers.

API migration

Use purchase("stars", username, amount), purchase("premium", username, months=3), or purchase("ton", username, amount). Batch purchases use purchase([...]) and retain one combined TON submission. The separate purchase_stars, purchase_premium, topup_gram, topup_ton, and batch_purchase methods are removed.

Function-style FragmentAPI.methods adapters, list_sessions, ConfigError, VerificationError, and old EvmInvoice / EvmPaymentResult names are removed. Use FragmentClient, get_sessions, ConfigurationError, FragmentAPIError, and the External* classes. Payment method aliases gram and usdt_gram are removed; use ton and usdt_ton.

Shared authentication has been removed. Fragment requests now use your own cookie session, with explicit authentication using your own wallet when needed.

Area What changed
Authentication The built-in public auth seed, automatic shared-wallet proof, and shared-mode options are removed
Sessions Fragment HTTP operations require user-owned cookies; missing cookies fail before any request
Batches All batches return BatchResult; the shared-mode result type is removed
Profile get_profile() reads the full page header; the removed /my/profile route is no longer requested
Account fields Name, photo, wallet address and label; username is empty because the header does not expose it
API errors KYC-specific classification is removed; errors use FragmentAPIError
Giveaways Stars recipient search sends only query, matching the current Fragment interface
Marketplace Wallet owners and history support the current gram.org/address/ explorer links

Remove shared_auth_seed and wallet_auth constructor arguments and stop using nokyc_mode or NoKycBatchResult. Supply cookies directly, load them from session storage, or call FragmentClient.authenticate() with your own wallet before constructing the client. No built-in wallet is used for authentication or payment.

ProfileInfo.identity_verified and ProfileInfo.wallet_verified were removed in 14.1.0 with the old profile page.

Live checks on November 2, 2026 returned request IDs and unsigned native-TON transactions for Stars, Premium, both giveaway types, and Ads top-ups without a verification challenge in the tested session. No payments were submitted. Withdrawals and asset mutations require valid operation links or assets and were not exercised by that check.

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 PyPI with pip install fragment-api-py.

Optional integrations:

Extra Installation
Redis storage pip install "fragment-api-py[redis]"
Terminal QR rendering pip install "fragment-api-py[qr]"
Development tools pip install "fragment-api-py[dev]"

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
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
Purchases and giveaways
Data models
Exceptions and limits

Marketplace and operations

Marketplace and search
Asset management
Executable examples
Issue tracker

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.

Support with TON

TON address

UQAcsdD09x9dzj7Jc-MznN-SLUxPPMmwKQxsC2Ax_F03TBAH


GitHub   /   Documentation   /   MIT License

Metadata

Release files for fragment-api-py 14.2.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-py 14.2.0
File Size Uploaded Provenance Actions
fragment_api_py-14.2.0.tar.gz 72.7 kB Without provenance Details for fragment_api_py-14.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fragment-api-py 14.2.0
File Interpreter ABI Platform Actions
fragment_api_py-14.2.0-py3-none-any.whl Python 3 none any Details for fragment_api_py-14.2.0-py3-none-any.whl

Total release size: 160.6 kB

Release files / fragment_api_py-14.2.0.tar.gz

Download URL fragment_api_py-14.2.0.tar.gz
Size 72.7 kB
Tags Source
SHA-256 checksum
How to use checksums
de0818eae4bc2d6755e2fb852792c6ab6b1f4ca769256ded563cb8d57b12d90a
BLAKE2b-256 checksum
How to use checksums
dfe2663221710defdca4e7e8296f51b07cf5048c7febe0d5ae1b3aae124e8803
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / fragment_api_py-14.2.0-py3-none-any.whl

Download URL fragment_api_py-14.2.0-py3-none-any.whl
Size 87.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4d5b91f2f8f2c42a7fb63fbfc87c291988e0e9c1a865edbae30fe6b05fa33a5
BLAKE2b-256 checksum
How to use checksums
0c7a6ecfada54fa0cec496647041f8b94074231b17c825900a04db2612807604
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for fragment-api-py 14.2.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

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