Skip to main content

A Python library to handle steps in pyrogram framework.

Project description

Pyrostep

Downloads Python Pyrogram

A Python library to handle steps in pyrogram framework.

Pyrostep helps you to use pyrogram:

  • very easy step handling, waiting for answer, ...
  • change connection timeout, retries, etc.

Updated to 2.8.2

In this update, pyrostep completely changed ...

install

python3 -m pip install -U pyrostep

Learn

to start with pyrostep, you have to do two steps:

  1. import pyrostep
  2. listen on which client you want
import pyrostep
# ...
cli = Client(...)
pyrostep.listen(cli)

step handling

step handling have two methods:

  • pyrostep.register_next_step(...)
  • pyrostep.unregister_steps(...)

register_next_step register next step, and unregister_steps removes step for user.

see example: ( see examples )

# ...

async def step1(client, msg):
    await msg.reply(
        "Send your name?"
    )
    pyrostep.register_next_step(
        msg.from_user.id,
        step2
    )

async def step2(client, msg):
    await msg.reply(
        f"Your name is {msg.text}"
    )

# ...

wait_for method

if you dont like step handling, can use this method.

see example: ( see examples )

# ...

async def get_name(client, msg):
    await msg.reply(
        "Send your name?"
    )
    answer = await pyrostep.wait_for(
        msg.from_user.id
    )
    await msg.reply(
        f"Your name is {answer.text}"
    )

# ...

about safe_idle

I recommended use pyrostep.safe_idle instead of pyrogram.idle when using pyrostep.

why? safe_idle works like pyrogram.idle, but pyrogram.idle works with asyncio.Task, and this may cause a crash in a program where asyncio.Future is used.

safe_idle not handle signals.

example: ( see examples )

# ...
async def main():
    await app.start()
    await pyrostep.safe_idle()
    await app.stop()

app.run(main())

Other packages and shortcuts

Connection

connection_max_retries method:

Change connection max retries. (default 3)

invoke_max_retries method:

Change invoke max retries. (default 5)

session_start_timeout method:

Change start timeout. (default 1)

session_max_retries method:

Change session max retries ( and tcp connection mode ).

  • TCP Connection Modes:
    • TCPFull
    • TCPAbridged
    • TCPIntermediate
    • TCPAbridgedO
    • TCPIntermediateO

Shortcuts

import shortcuts:

from pyrostep import shortcuts

Now see methods:

split_list splites lst list:

>>> shortcuts.split_list([1, 2, 3, 4, 5, 6], 2)
# [[1, 2], [3, 4], [5, 6]]
>>> shortcuts.split_list([1, 2, 3], 2)
# [[1, 2], [3]]

keyboard creates ReplyKeyboardMarkup from your list:

buttons = [
    [
        ["Top Left"], ["Top Right"]
    ],
    [
        ["Bottom | Request Contact", True, "request_contact"]
    ]
]
kb = shortcuts.keyboard(buttons)

inlinekeyboard creates InlineKeyboardMarkup from your list:

buttons = [
    [
        ["Top Left", "data_1"], ["Top Right", "data_2"]
    ],
    [
        ["Bottom", "Your URL", "url"]
    ]
]
ikb = inlinekeyboard(buttons)

validation_channels checks user already in channels or not:

user_id = 56392019
channels = [-102792837, -10823823, 'channel_username']

is_joined = await validation_channels(
    app, user_id, channels
)
# ...
async def invite(app, id, channels) -> None:
    print(
        f"User {id} is not member of channels ({channels})"
    )

is_joined = await validation_channels(
    app, user_id, channels,
    invite_func=invite
)

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

pyrostep-2.8.2.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

pyrostep-2.8.2-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file pyrostep-2.8.2.tar.gz.

File metadata

  • Download URL: pyrostep-2.8.2.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.2

File hashes

Hashes for pyrostep-2.8.2.tar.gz
Algorithm Hash digest
SHA256 73ce813cb48a2b6a0caf41801212b4df075b3ebc59aa6d3013449ea0927fcc16
MD5 9974aa1f80b47d911ea75bdf90e028e0
BLAKE2b-256 471ad4de604fc4c56a3754675c4c4b819a85b6516d5be07cb0b002d405e5e984

See more details on using hashes here.

File details

Details for the file pyrostep-2.8.2-py3-none-any.whl.

File metadata

  • Download URL: pyrostep-2.8.2-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.2

File hashes

Hashes for pyrostep-2.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8eaf3b5e9ac81005d3ba4dbad8322137f6e57ed83a4666505bc812848a581ea9
MD5 3e115a4de312ed52a4debb7c48040342
BLAKE2b-256 abe58e48c7bca10173298203d7ca571b12bca6039dbfbc4cb1b67c2647b5cf10

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