Official Python SDK for the MyStars FaaS API — buy Telegram Stars & Premium for any @username, paid in TON or USDT.
Project description
mystars-faas
Official Python SDK for the MyStars FaaS API — buy Telegram Stars & Premium for any
@username, paid in TON or USDT (TON).
Sync + async clients, exact-Decimal money, typed errors, automatic retries + idempotency, webhook
verification, a retail-markup calculator, and dependency-free on-chain payload builders.
Compatible with FaaS API v1.9.0. Requires Python ≥ 3.9. Only runtime dependency:
httpx.
📖 Full interactive API reference: mystars.tg/docs. SDK method/function reference: api-python.md. Changelog: CHANGELOG.md.
Install
pip install mystars-faas
Keys are issued in the MyStars Telegram bot — open @my_stars_tg_bot,
tap API access, copy your X-Api-Key.
Runnable examples live in examples/ (quickstart + webhook receiver).
Quick start
import os
from mystars_faas import MyStarsClient
client = MyStarsClient.production(os.environ["MYSTARS_API_KEY"])
quote = client.get_pricing(type="stars", quantity=100, payment_currency="ton")
print("pay", quote.amount, quote.currency)
check = client.check_recipient("durov", type="stars")
if not check.eligible:
raise SystemExit(check.telegram_message)
order = client.create_order( # an Idempotency-Key is generated + reused on retry
type="stars", recipient="durov", quantity=100,
callback_url="https://your-app.example.com/webhooks/mystars",
)
# Pay order.payment.amount to order.payment.pay_to_address with the comment order.payment.memo.
print(order.payment)
final = client.wait_for_order(order.order_id, on_update=lambda o: print("status:", o.status))
print("done:", final.status, final.purchase_tx)
Async
from mystars_faas import AsyncMyStarsClient
async with AsyncMyStarsClient.production(key) as client:
quote = await client.get_pricing(type="premium", months=3, payment_currency="usdt_ton")
async for order in client.aiter_orders(status="delivered"):
...
Webhooks
from mystars_faas import WebhookVerifier
verifier = WebhookVerifier(WEBHOOK_SECRET)
event = verifier.verify(raw_body, request.headers["X-Faas-Signature"]) # raises on bad signature
# event.order_id, event.status — dedup on order_id (delivery is at-least-once)
Handles the 24h "current,previous" rotation header automatically. FastAPI / Flask route factories
live in mystars_faas.integrations.fastapi / .flask (install mystars-faas[fastapi] / [flask]).
Your own retail markup
from mystars_faas import apply_retail_markup
quote = client.get_pricing(type="stars", quantity=100, payment_currency="usdt_ton")
retail = apply_retail_markup(quote, margin_pct=15, pass_through_processing_fee=True)
print(retail.total) # what to charge your customer (Decimal-exact, two-stage cent-ceil)
print(retail.profit) # your gross margin
Pay an order (non-custodial)
from mystars_faas import build_payment_request
req = build_payment_request(order.payment)
print(req.ton_deeplink) # ton://transfer/... (TON), or req.ton_connect for a TON Connect message
Holds no keys. Errors are typed subclasses of MyStarsAPIError (RecipientIneligibleError,
RateLimitedError, …); the client retries transient failures (network, timeout, 502/503/504, 500,
general 429 — honoring Retry-After, including the HTTP-date form) automatically and
idempotency-safely. A response body larger than 4 MB is rejected (response_too_large) instead of
being buffered whole.
Errors
| Class | HTTP | TS-SDK alias |
|---|---|---|
MyStarsValidationError |
— (client-side) | — |
BadRequestError |
400 | — |
AuthenticationError |
401 | UnauthorizedError |
PermissionDeniedError |
403 | ForbiddenError |
NotFoundError |
404 | — |
ConflictError / IdempotencyConflictError / OrderNotCancellableError |
409 | — |
RecipientIneligibleError |
422 | — |
RateLimitedError |
429 | — |
InternalServerError / ServiceUnavailableError |
500 / 503 | — |
MyStarsTransportError / TimeoutError_ |
— (no response) | — |
UnauthorizedError and ForbiddenError are exported aliases of AuthenticationError /
PermissionDeniedError so code written against the TypeScript SDK's names catches the same error.
CLI
mystars-faas --api-key "$MYSTARS_API_KEY" pricing --type stars --quantity 100 --currency ton
mystars-faas orders-create --type stars --recipient durov --quantity 100 --pay
# Verify a webhook offline. Prefer the env var — a --secret on argv is visible in `ps`.
export MYSTARS_WEBHOOK_SECRET="…"
mystars-faas webhook-verify --body "$RAW_BODY" --signature "$X_FAAS_SIGNATURE"
webhook-verify reads the secret from MYSTARS_WEBHOOK_SECRET (preferred) or --secret; the env
var wins when both are set, because a command-line --secret leaks via the process list and shell
history.
Project details
Release history Release notifications | RSS feed
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 mystars_faas-0.1.1.tar.gz.
File metadata
- Download URL: mystars_faas-0.1.1.tar.gz
- Upload date:
- Size: 36.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acafcfd712a91437f3fca574a5bf6883ea4e864562dc5d9501e12cf2dd95776a
|
|
| MD5 |
6de7c1373b3370a57060c9456e9e5bbe
|
|
| BLAKE2b-256 |
aca2a17fffcf8e37947d5e5e8c5a85e56f0662d3eec36f73a9d666cc0658f479
|
File details
Details for the file mystars_faas-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mystars_faas-0.1.1-py3-none-any.whl
- Upload date:
- Size: 46.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfd5a7e2d22087a881cdf3432a1391ce8adc8d624f1328323ea2b277781f4ce7
|
|
| MD5 |
04cbcc50514972ddc66365ad3ff6d458
|
|
| BLAKE2b-256 |
9c48ad2f783544bd3b4cc98890f7612355b891b49b9665cf6aa702bd46659b5c
|