start()¶
- Client.start()
Start the client.
This method connects the client to Telegram and, in case of new sessions, automatically manages the authorization process using an interactive prompt or a QR code.
Note
Install the
qrcodepackage to use QR code authorization:pip install qrcode- Parameters:
use_qr (
bool, optional) – Use QR code authorization instead of the interactive phone-number prompt. Only applies to new (unauthorized) sessions. Defaults to False.except_ids (List of
int, optional) – List of already logged-in user IDs to exclude during QR authorization, preventing the same account from being logged in twice. Only used when use_qr is True.
- Returns:
Client– The started client itself.- Raises:
ConnectionError – In case you try to start an already started client.
Example
import asyncio from pyrogram import Client async def main(): app = Client("my_account") await app.start() ... await app.stop() asyncio.run(main())
- Example with QR code:
import asyncio from pyrogram import Client async def main(): app = Client("my_account", api_id=12345, api_hash="...") await app.start(use_qr=True) print(await app.get_me()) await app.stop() asyncio.run(main())