Skip to main content

python library Client for iranian messager sroosh

Project description

pysroosh

Python client for Sroosh, built on Telethon (MTProto).

Install

pip install pysroosh

Optional extras:

pip install pysroosh[redis]
pip install pysroosh[postgres]

Quick start

from pysroosh import Client

bot = Client("my_session")

@bot.on_message()
async def handler(client, message):
    await message.reply("Hello!")

bot.run()

Sync usage

from pysroosh.sync import Client

bot = Client("my_session")

@bot.on_message()
def handler(client, message):
    message.reply("Hello!")

bot.run()

Events

  • on_message
  • on_edited
  • on_callback_query
  • on_inline_query
  • on_chat_action
  • on_user_update
  • on_message_deleted
  • on_message_read
  • on_error

Filters

from pysroosh import filters

@bot.on_message(filters.text & filters.private)
@bot.on_message(filters.command("start"))
@bot.on_message(filters.photo | filters.video)

Buttons

from pysroosh import Button

keyboard = Button.build_inline([
    Button.inline("Option 1", b"opt1"),
    Button.inline("Option 2", b"opt2"),
])
await bot.send_message(chat_id, "Choose:", buttons=keyboard)

FSM

from pysroosh.fsm import State, StateMachine
from pysroosh.storage import MemoryStorage

storage = MemoryStorage()
fsm = StateMachine(storage)

class Form:
    name = State()
    age = State()

Scheduler

from pysroosh.scheduler import MessageScheduler

scheduler = MessageScheduler(bot)
scheduler.schedule_interval("hourly", chat_id, "Hello!", interval=3600)

Admin

await bot.admin.ban_user(chat_id, user_id)
await bot.admin.mute_user(chat_id, user_id)
await bot.admin.purge_messages(chat_id, limit=100)

AFK

bot.afk.set_afk(True, reason="lunch")

@bot.on_message(filters.private & filters.incoming)
async def auto_reply(client, message):
    await bot.afk.handle(message)

Mirror

from pysroosh.mirror import MessageMirror

mirror = MessageMirror(bot)
mirror.add_route(source=-100123, targets=[-100456], add_prefix="[Mirror]")
await mirror.start()

CLI

pysroosh run bot.py
pysroosh validate bot.py
pysroosh version
pysroosh session-info my_session.session

Notes

This library uses Telethon as its transport, connecting with the public Sroosh api_id/api_hash by default (documented by the SrooshJS project). You may pass your own credentials to Client(session, api_id=..., api_hash=...).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysroosh-2.0.0.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysroosh-2.0.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file pysroosh-2.0.0.tar.gz.

File metadata

  • Download URL: pysroosh-2.0.0.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pysroosh-2.0.0.tar.gz
Algorithm Hash digest
SHA256 fb71fa0e025fa62f273f820f25b38e0924f2c44c1978dbb2b2dca7ddf40862fe
MD5 3a85f0094da4339002d9f1a72e8604fc
BLAKE2b-256 723f4f0760663d422c8528f984b9cb1f13076623eeabd43157d4c94bc7725d9e

See more details on using hashes here.

File details

Details for the file pysroosh-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: pysroosh-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pysroosh-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31b3b287880a8fb40e35e0bc9d68797e4e75483dd4676f5d976798b40b0832be
MD5 4757bbdc1d5adb2918903f0279d26997
BLAKE2b-256 e5ef3ad2cfc04cd8c1271e0ace841094aaf83c378a123bd16d32d175baba7a67

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page