Asynchronous library for Telegram bot API
Project description
Key Features
Asyncio and aiohttp based
All Telegram Bot API types and methods supported
Bot API rate limit support
Both long polling and webhooks supported
Fully type annotated (PEP 484)
Installation
aiotgbot is available on PyPI. Use pip to install it:
pip install aiotgbot
Requirements
Python >= 3.8
Using aiotgbot
from typing import AsyncIterator
from aiotgbot import (Bot, BotUpdate, HandlerTable, PollBot,
PrivateChatFilter, Runner)
from aiotgbot.storage_memory import MemoryStorage
handlers = HandlerTable()
@handlers.message(filters=[PrivateChatFilter()])
async def reply_private_message(bot: Bot, update: BotUpdate) -> None:
assert update.message is not None
name = (f'{update.message.chat.first_name} '
f'{update.message.chat.last_name}')
await bot.send_message(update.message.chat.id, f'Hello, {name}!')
async def run_context(runner: Runner) -> AsyncIterator[None]:
storage = MemoryStorage()
await storage.connect()
handlers.freeze()
bot = PollBot(runner['token'], handlers, storage)
await bot.start()
yield
await bot.stop()
await storage.close()
def main() -> None:
runner = Runner(run_context)
runner['token'] = 'some:token'
runner.run()
if __name__ == '__main__':
main()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiotgbot-0.17.18.tar.gz
(37.1 kB
view details)
Built Distribution
File details
Details for the file aiotgbot-0.17.18.tar.gz
.
File metadata
- Download URL: aiotgbot-0.17.18.tar.gz
- Upload date:
- Size: 37.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31cd56724bed82fbdb7cd011529bdd09ec47fb96dc7595ca1db4799f2f67b9ac |
|
MD5 | a4b6d69f64ca36d6bea6d9ab345c45d3 |
|
BLAKE2b-256 | 88cf552c12fdcd1f4c99bd793bdb56cd68b7a81ffbe77a6d4d0b4606a6e8a110 |
File details
Details for the file aiotgbot-0.17.18-py3-none-any.whl
.
File metadata
- Download URL: aiotgbot-0.17.18-py3-none-any.whl
- Upload date:
- Size: 40.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97f1b739dadb4555ef427c178df86bde11681fd0ee3ee0d5569a646d62e929c1 |
|
MD5 | d3fbff05d5fcca5526bf7c59e0245441 |
|
BLAKE2b-256 | 3aaeeca63c8ba08b09d0d6dcd7cb845cfe54c20852064c65f25078deb8777691 |