{"id":49216189,"url":"https://github.com/bohd4nx/pyfragment","last_synced_at":"2026-04-24T00:03:49.115Z","repository":{"id":322160413,"uuid":"1088393529","full_name":"bohd4nx/pyfragment","owner":"bohd4nx","description":"Async Python client for the Fragment API — a unified toolkit to manage Telegram assets: purchase Stars and Premium, top up TON and Ads balances, run giveaways, manage anonymous numbers, and explore the marketplace for usernames, numbers, and gifts.","archived":false,"fork":false,"pushed_at":"2026-04-13T23:21:53.000Z","size":318,"stargazers_count":35,"open_issues_count":4,"forks_count":8,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-04-14T00:29:22.777Z","etag":null,"topics":["fragment","fragment-sdk","fragment-stars","fragment-ton","telegram","telegram-premium","ton"],"latest_commit_sha":null,"homepage":"https://t.me/bohd4nx","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bohd4nx.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-02T21:57:08.000Z","updated_at":"2026-04-13T23:00:53.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/bohd4nx/pyfragment","commit_stats":null,"previous_names":["bohd4nx/fragmentapi","bohd4nx/pyfragment"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/bohd4nx/pyfragment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bohd4nx%2Fpyfragment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bohd4nx%2Fpyfragment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bohd4nx%2Fpyfragment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bohd4nx%2Fpyfragment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bohd4nx","download_url":"https://codeload.github.com/bohd4nx/pyfragment/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bohd4nx%2Fpyfragment/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32203363,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-23T20:19:26.138Z","status":"ssl_error","status_checked_at":"2026-04-23T20:19:23.520Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fragment","fragment-sdk","fragment-stars","fragment-ton","telegram","telegram-premium","ton"],"created_at":"2026-04-24T00:03:45.337Z","updated_at":"2026-04-24T00:03:49.107Z","avatar_url":"https://github.com/bohd4nx.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://www.bohd4n.dev/assets/projects/pyfragment.svg\" alt=\"Fragment Logo\" width=\"120\" height=\"120\" style=\"border-radius: 24px;\"\u003e\n\n  \u003ch1 style=\"margin-top: 24px;\"\u003eFragment API\u003c/h1\u003e\n\n  \u003cp style=\"font-size: 18px; margin-bottom: 24px;\"\u003e\n    \u003cb\u003eAsync Python client for the Fragment API — a unified toolkit to manage Telegram assets: purchase Stars and Premium, top up TON and Ads balances, run giveaways, manage anonymous numbers, and explore the marketplace for usernames, numbers, and gifts.\u003c/b\u003e\n  \u003c/p\u003e\n\n[![PyPI version](https://img.shields.io/pypi/v/pyfragment?style=flat\u0026color=blue)](https://pypi.org/project/pyfragment/)\n[![PyPI downloads](https://img.shields.io/pypi/dm/pyfragment?style=flat\u0026color=brightgreen)](https://pypi.org/project/pyfragment/)\n[![Python](https://img.shields.io/badge/Python-3.10+-3776AB?style=flat\u0026logo=python\u0026logoColor=white)](https://python.org)\n[![License](https://img.shields.io/github/license/bohd4nx/pyfragment?style=flat\u0026color=lightgrey)](LICENSE)\n[![Stars](https://img.shields.io/github/stars/bohd4nx/pyfragment?style=flat\u0026color=yellow)](https://github.com/bohd4nx/pyfragment/stargazers)\n[![CI](https://img.shields.io/github/actions/workflow/status/bohd4nx/pyfragment/ci.yml?style=flat\u0026label=tests\u0026logo=github)](https://github.com/bohd4nx/pyfragment/actions)\n\n[Report Bug](https://github.com/bohd4nx/pyfragment/issues) · [Request Feature](https://github.com/bohd4nx/pyfragment/issues) · [**Donate TON**](https://app.tonkeeper.com/transfer/UQCppfw5DxWgdVHf3zkmZS8k1mt9oAUYxQLwq2fz3nhO8No5)\n\n\u003c/div\u003e\n\n\u003e **Disclaimer:** This project is not affiliated with, endorsed by, or in any way officially connected with [Fragment](https://fragment.com) or [Telegram](https://telegram.org).\n\n---\n\n## Installation\n\n```bash\npip install pyfragment\n```\n\nTo install the latest unreleased changes from the `dev` branch:\n\n```bash\npip install git+https://github.com/bohd4nx/pyfragment.git@dev\n```\n\nRequires Python 3.10+.\n\n---\n\n## Configuration\n\n| Parameter        | Type          | Default  | Description                                              |\n| ---------------- | ------------- | -------- | -------------------------------------------------------- |\n| `seed`           | `str`         | —        | 24-word TON wallet mnemonic                              |\n| `api_key`        | `str`         | —        | Tonapi key from [tonconsole.com](https://tonconsole.com) |\n| `cookies`        | `dict \\| str` | —        | Fragment session cookies                                 |\n| `wallet_version` | `str`         | `\"V5R1\"` | `\"V4R2\"` or `\"V5R1\"`                                     |\n| `timeout`        | `float`       | `30.0`   | HTTP request timeout in seconds                          |\n\n---\n\n## Credentials\n\n**Fragment cookies** — log in to [fragment.com](https://fragment.com) and connect your TON wallet. You can get cookies in two ways:\n\n- **Automatically** (recommended) — use `get_cookies_from_browser()`, which reads them directly from your browser's on-disk store. No extension needed:\n  ```python\n  from pyfragment.utils import get_cookies_from_browser\n  result = get_cookies_from_browser(\"chrome\")  # or \"firefox\", \"edge\", \"brave\", ...\n  # result.cookies — dict[str, str] to pass to FragmentClient\n  # result.expires — ISO 8601 expiry of stel_ssid, or None for session cookies\n  ```\n- **Manually** — install [Cookie Editor](https://chromewebstore.google.com/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm) and export these four keys: `stel_ssid`, `stel_dt`, `stel_token`, `stel_ton_token`. Pass them as a `dict` or JSON string.\n\nRefresh when you get authentication errors.\n\n**Tonapi key** — generate at [tonconsole.com](https://tonconsole.com).\n\n**Seed phrase** — 24-word mnemonic from your TON wallet (Tonkeeper → Settings → Backup). Never share it.\n\n---\n\n## Usage\n\n```python\nimport asyncio\nfrom pyfragment import (\n    FragmentClient,\n    FragmentError,       # base — catches everything below\n    UserNotFoundError,   # username doesn't exist on Fragment\n    WalletError,         # insufficient balance or misconfiguration\n    CookieError,         # cookies are missing or expired\n    TransactionError,    # on-chain broadcast failed\n    ConfigurationError,  # invalid argument (months, amount, etc.)\n    FragmentAPIError,    # unexpected Fragment API response\n)\n\n\nasync def main() -\u003e None:\n    async with FragmentClient(\n        seed=\"word1 word2 ... word24\",  # 24-word TON wallet mnemonic\n        api_key=\"YOUR_TONAPI_KEY\",       # from tonconsole.com\n        cookies={\n            \"stel_ssid\": \"...\",\n            \"stel_dt\": \"...\",\n            \"stel_token\": \"...\",\n            \"stel_ton_token\": \"...\",\n        },\n    ) as client:\n        try:\n            # Purchase 6 months of Telegram Premium\n            result = await client.purchase_premium(\"@username\", months=6)\n            print(f\"{result.amount} months of Premium successfully sent to {result.username} | tx: {result.transaction_id}\")\n\n            # Purchase 500 Stars\n            result = await client.purchase_stars(\"@username\", amount=500)\n            print(f\"{result.amount} Stars successfully sent to {result.username} | tx: {result.transaction_id}\")\n\n            # Top up 10 TON to Telegram balance\n            # wallet must hold at least amount + ~0.056 TON for gas\n            result = await client.topup_ton(\"@username\", amount=10)\n            print(f\"{result.amount} TON successfully sent to {result.username} | tx: {result.transaction_id}\")\n\n        except UserNotFoundError:\n            print(f\"User was not found on fragment.com — check the username and try again.\")\n        except WalletError as e:\n            print(f\"Wallet error — insufficient balance or misconfiguration: {e}\")\n        except CookieError:\n            print(\"Authentication failed — session cookies are missing or expired. Refresh them and retry.\")\n        except TransactionError as e:\n            print(f\"Transaction failed to broadcast on-chain: {e}\")\n        except ConfigurationError as e:\n            print(f\"Invalid argument: {e}\")\n        except FragmentAPIError as e:\n            print(f\"Unexpected response from Fragment API: {e}\")\n        except FragmentError as e:\n            # catch-all for any other pyfragment error\n            print(f\"Unexpected error: {e}\")\n\n\nasyncio.run(main())\n```\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\n### Made with ❤️ by [@bohd4nx](https://t.me/bohd4nx)\n\n**Star ⭐ this repo if you found it useful!**\n\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbohd4nx%2Fpyfragment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbohd4nx%2Fpyfragment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbohd4nx%2Fpyfragment/lists"}