Having your project set up and your account authorized, it's time to play with the API. Let's start!
The easiest and recommended way to interact with Telegram is via the high-level Pyrogram methods and types, which are named after the Telegram Bot API.
Here's a simple example:
from pyrogram import Client app = Client("my_account") app.start() print(app.get_me()) app.send_message("me", "Hi there! I'm using **Pyrogram**") app.send_location("me", 51.500729, -0.124583) app.stop()
You can also use Pyrogram in a context manager with the with statement. The Client will automatically
:meth:`start <pyrogram.Client.start>` and :meth:`stop <pyrogram.Client.stop>` gracefully, even in case of unhandled
exceptions in your code:
from pyrogram import Client app = Client("my_account") with app: print(app.get_me()) app.send_message("me", "Hi there! I'm using **Pyrogram**") app.send_location("me", 51.500729, -0.124583)
More examples on GitHub.