run()

Client.run()

Start the client, idle the main script and finally stop the client.

When called without an argument, acts as a convenience method that calls start(), idle() and stop() in sequence.

If a coroutine is passed, runs it until complete without managing the client lifecycle. Equivalent to asyncio.run() but reuses the current event loop.

Parameters:

coroutine (Coroutine, optional) – Pass a coroutine to run it until it completes.

Raises:

raises ConnectionError: In case you try to run an already started client.

Example

from pyrogram import Client

app = Client("my_account")
app.run()
from pyrogram import Client

app = Client("my_account")

async def main():
    async with app:
        print(await app.get_me())

app.run(main())