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

Single-submission batches, durable payment recovery, and coordinated payer access.

Area What changed
Authentication Restricted wallet-proof sessions remain separate from the real payer
Transport A reusable client-owned HTTP session with cached API hashes
Payments Signed intent is journaled before broadcast; interrupted payments can be reconciled
Wallets V4R2, V5R1, HighloadV2, HighloadV3R1, and Telegram WalletTg configuration
Batches One combined wallet submission with per-invoice outcomes
Storage SQLite payment journal, local process locks, and shared-store/distributed-lock extension points
Parsing Table-fragment handling, decimal preservation, responsive statuses, and merged gift filters
Validation Strict integer inputs, original giveaway package limits, and capability guards

Choose your workflow

Workflow Configuration Result
Account browsing Your Fragment cookies Marketplace and user-owned account data
Restricted session No cookies; wallet authentication Allowed public and purchase workflows
External TON signing A complete sender account or an offline-derived payer account, without automatic payment credentials PreparedTransaction
Automatic TON payment Payer seed and blockchain API key Broadcast receipt with explicit confirmation state
EVM payment Supported EVM payment method An invoice for external payment

Account operations require a user-owned cookie session. Native automatic payments in cookie mode additionally require a wallet-connected session.

Restricted wallet authentication does not bypass Fragment verification requirements. The shared authentication wallet is separate from the configured payer.

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
Understand restricted mode Wallet 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

batch_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, gram TON TON Prepare or broadcast
usdt_ton, usdt_gram TON USDT Prepare or broadcast
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.
  • Never deposit funds into the shared authentication wallet.
  • 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   /   Telegram   /   MIT License

Metadata

Release files for fragment-api-py 14.0.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.0.0
File Size Uploaded
fragment_api_py-14.0.0.tar.gz 69.5 kB Details

Built distribution (wheel)

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

Total release size: 156.9 kB

Release files / fragment_api_py-14.0.0.tar.gz

Download URL fragment_api_py-14.0.0.tar.gz
Size 69.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5fb57bd2fa1c3b9171ad6121d8a96485126d363629995afe5e0707dfea61d946
BLAKE2b-256 checksum
How to use checksums
dae284492b29161b13220dcf6d3452eea7e42231d7425a540555e9fdbb307064
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.34.2

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

Download URL fragment_api_py-14.0.0-py3-none-any.whl
Size 87.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5f14da0e6582366b7278b7319fc6f968435e473de6acc361b05b724d4142c06
BLAKE2b-256 checksum
How to use checksums
55e67d3556e17d24ba33e1fcbb08e99bc23166ad37745a0ffc407b0e281d7476
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.34.2

Release history Release notifications | RSS feed

This release

14.0.0 This release

2 release files

12.1.0

2 release files

12.0.0

2 release files

11.0.0

2 release files

10.0.0

2 release files

9.0.2

2 release files

9.0.1

2 release files

9.0.0

2 release files

8.1.0

2 release files

8.0.0

2 release files

7.0.0

2 release files

6.1.0

2 release files

6.0.1

2 release files

5.0.1

2 release files

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