2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Enhance API by adding support for Context Managers. Closes #122

A batch script would be as simple as this example:

from pyrogram import Client

with Client("...") as app:
    app.send_message("haskell", "hi")
This commit is contained in:
Dan 2018-09-17 18:53:04 +02:00
parent cd3649448c
commit f850d6352e

View File

@ -183,6 +183,13 @@ class Client(Methods, BaseClient):
self.dispatcher = Dispatcher(self, workers) self.dispatcher = Dispatcher(self, workers)
def __enter__(self):
self.start()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.stop()
@property @property
def proxy(self): def proxy(self):
return self._proxy return self._proxy