Асинхронная Python-библиотека для работы с Boosty.to API
Асинхронная Python-библиотека для Boosty.to API. Позволяет управлять подписками, постами, донатами и автоматизировать взаимодействие с платформой.
Зависимости:
httpx — асинхронный HTTP-клиентpydantic v2 — валидация данныхpydantic-settings — конфигурация через ENVpip install boostylibили через uv:
uv add boostylibSyncBoostyClient для не-async кодаfrom boostylib import BoostyClient
async with BoostyClient(access_token="token") as client:
status = await client.subscriptions.verify_subscription("blog", "user_id")
if status.is_subscribed:
print(f"Level: {status.level.name}, Paid: {status.is_paid}")async with BoostyClient(access_token="...") as client:
async for sub in client.subscriptions.iter_subscribers("blog"):
if sub.is_paid:
print(f"{sub.name}: {sub.email} — {sub.payments} RUB")from boostylib.builders import PostBuilder
post = (PostBuilder()
.title("Premium Content")
.text("Exclusive material")
.access_level(level_id="premium_id")
.build())
await client.posts.create_post("blog", post)from boostylib import EventType
@client.on(EventType.NEW_SUBSCRIPTION)
async def on_subscribe(event):
await client.comments.create_comment(
event.blog_username, event.welcome_post_id,
f"Welcome {event.user.name}!")
@client.on(EventType.NEW_COMMENT)
async def on_comment(event):
await client.comments.create_comment(
event.blog_username, event.post_id,
f"Thanks, {event.user.name}!",
reply_to=str(event.comment_id))
async with client:
await client.start_polling()from pathlib import Path
media = await client.media.upload_file(
Path("./source.zip"), filename="source.zip")
post = (PostBuilder()
.title("Sources")
.file(media_id=media.id, filename=media.filename)
.access_level(level_id="premium")
.build())from boostylib.sync import SyncBoostyClient
with SyncBoostyClient(access_token="...") as client:
user = client.users.get_current_user()
subscribers = client.subscriptions.get_subscribers("blog")Через переменные окружения:
BOOSTY_ACCESS_TOKEN=...
BOOSTY_REFRESH_TOKEN=...
BOOSTY_DEVICE_ID=...
BOOSTY_TIMEOUT=30
BOOSTY_MAX_RETRIES=3
BOOSTY_POLL_INTERVAL=60
Или программно:
from boostylib import BoostySettings
settings = BoostySettings(timeout=10.0, max_retries=5, debug=True)
client = BoostyClient(settings=settings, access_token="...")mypy --strictСвязаться: BazZziliuS