Skip to main content

Modern asynchronous library for Telegram Bot API

Project description

Telegram Async

Python Version aiohttp License Downloads Code style: black Type checked Tests

An asynchronous Telegram API client library for Python, using aiohttp for efficient communication with Telegram servers.

๐Ÿ‘ค Author

Denys Ostrovskyi

๐Ÿ“‹ Table of Contents

โœจ Features

  • โœ… Fully asynchronous - uses async/await for maximum performance
  • โœ… Full Telegram Bot API 9.6 - complete coverage including:
    • ๐Ÿค– Managed Bots - Create and manage sub-bots
    • ๐Ÿ“Š Enhanced Polls - Multiple correct answers, revoting, descriptions
    • ๐Ÿ’ณ Paid Media - Premium content for Telegram Stars
    • ๐Ÿ”— Invite Links - Full management with limits/expiration
    • ๐Ÿ“Œ Pin/Unpin Messages - Complete pinning support
    • ๐Ÿšช Join Requests - Approve/decline membership
    • ๐Ÿ” Chat Permissions - Granular member control
    • ๐Ÿ‘‘ Admin Rights - Set/get administrator rights
  • โœ… Session management - automatic connection renewal
  • โœ… Webhook support - easy configuration for receiving updates
  • โœ… Multimedia sending - photos, videos, documents, audio
  • โœ… Inline and reply keyboards - interactive messages
  • โœ… Rate limiting - automatic adaptation to API limits
  • โœ… Full typing - support for IDEs and type checkers
  • โœ… Error handling - advanced retry system and exception handling
  • โœ… Multilingualism - support for different languages in bot responses
  • โœ… Middleware - request processing system
  • โœ… Unit tests - 36 tests with comprehensive coverage

๐Ÿ”ง Requirements

  • Python 3.7 or later
  • aiohttp >= 3.8.0
  • Telegram bot account (token from @BotFather)

๐Ÿ“ฆ Installation

Installation from PyPI

pip install telegram-async

Installation from Source

git clone https://github.com/Denba236/telegram-async.git
cd telegram-async
pip install -e .

Installation with Dev Dependencies

pip install -e ".[dev]"

๐Ÿš€ Quick Start

Minimal Bot

from telegram_async import Bot, Dispatcher, Router

TOKEN = "YOUR_BOT_TOKEN"

bot = Bot(token=TOKEN)
dp = Dispatcher(bot)
router = Router()

@router.command("start")
async def cmd_start(ctx):
    await ctx.reply("Hello! Use /help for commands.")

@router.message()
async def echo(ctx):
    await ctx.reply(ctx.text)

dp.include_router(router)

if __name__ == "__main__":
    dp.run_polling(bot)

๐Ÿ“š API Documentation

Full API documentation with examples for all 115+ methods:

  • API 9.6 Full Support Guide - Complete documentation for all new features:

    • ๐Ÿค– Managed Bots - Create and manage sub-bots
    • ๐Ÿ“Š Enhanced Polls - Multiple correct answers, revoting, descriptions
    • ๐Ÿ’ณ Paid Media - Premium content for Telegram Stars
    • ๐Ÿ”— Invite Links - Full management with limits/expiration
    • ๐Ÿ“Œ Pin/Unpin Messages - Complete pinning support
    • ๐Ÿšช Join Requests - Approve/decline membership
    • ๐Ÿ” Chat Permissions - Granular member control
    • ๐Ÿ‘‘ Admin Rights - Set/get administrator rights
  • Colored Buttons Guide - Guide for colored buttons (API 9.4+)

  • Migration Guide - How to migrate to new structure

  • Restructure Summary - Project improvements

๐Ÿ“– Usage Examples

Check out the examples/ directory for complete working examples:

  • examples/main.py - Basic echo bot
  • examples/examples_api_95.py - API 9.5 features
  • examples/examples_colored_buttons.py - Colored buttons guide
  • examples/examples_new_features.py - 20+ feature examples

Run any example:

python examples/main.py

๐Ÿงช Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=telegram_async --cov-report=html

# Run specific test file
pytest tests/test_basic.py
pytest tests/test_api_96.py

# Run with verbose output
pytest -v

Test Results: 36 tests passing โœ…

๐Ÿ—๏ธ Project Structure

telegram_async/
โ”œโ”€โ”€ examples/              # All example files
โ”œโ”€โ”€ tests/                 # Test suite
โ”‚   โ”œโ”€โ”€ test_basic.py     # Basic tests
โ”‚   โ””โ”€โ”€ test_api_96.py    # API 9.6 tests
โ”œโ”€โ”€ docs/                  # Documentation
โ”‚   โ”œโ”€โ”€ API_96_FULL_SUPPORT.md
โ”‚   โ””โ”€โ”€ COLORED_BUTTONS_GUIDE.md
โ”œโ”€โ”€ telegram_async/        # Main package
โ”‚   โ”œโ”€โ”€ client/           # API client
โ”‚   โ”œโ”€โ”€ dispatcher/       # Dispatcher & Router
โ”‚   โ”œโ”€โ”€ exceptions/       # Exceptions
โ”‚   โ”œโ”€โ”€ filters/          # Filter system
โ”‚   โ”œโ”€โ”€ fsm/              # Finite State Machine
โ”‚   โ”œโ”€โ”€ handlers/         # Handler utilities
โ”‚   โ”œโ”€โ”€ keyboards/        # Keyboard builders
โ”‚   โ”œโ”€โ”€ middleware/       # Middleware
โ”‚   โ”œโ”€โ”€ telegram_types/   # Telegram types
โ”‚   โ”œโ”€โ”€ utils/            # Utilities
โ”‚   โ””โ”€โ”€ contrib/          # Community modules
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ MIGRATION_GUIDE.md
โ”œโ”€โ”€ RESTRUCTURE_SUMMARY.md
โ”œโ”€โ”€ pyproject.toml
โ””โ”€โ”€ .env.example

๐ŸŒ Multilingualism

The library supports internationalization (i18n):

from telegram_async.utils import I18n

i18n = I18n(locales_dir='locales', default_locale='en')

# In handler
@router.command("start")
async def cmd_start(ctx):
    greeting = await i18n.gettext(ctx.user_id, "Hello!")
    await ctx.reply(greeting)

๐Ÿค Contribution

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Contact and Support

๐Ÿ“Š Statistics

  • Total Methods: 115+
  • API Version: 9.6 (Latest)
  • Test Coverage: 36 tests
  • Python Versions: 3.7+
  • External Dependencies: 1 (aiohttp)

Made with โค๏ธ by Denys Ostrovskyi

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telegram_async-3.13.1.tar.gz (138.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telegram_async-3.13.1-py3-none-any.whl (154.4 kB view details)

Uploaded Python 3

File details

Details for the file telegram_async-3.13.1.tar.gz.

File metadata

  • Download URL: telegram_async-3.13.1.tar.gz
  • Upload date:
  • Size: 138.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for telegram_async-3.13.1.tar.gz
Algorithm Hash digest
SHA256 52d6fa9c58d4c6356dd321a5b43358d17b07d6d2df1f0aa2249aa96cb136c6ef
MD5 3e22571c8a0c86b9a1e53202513d30b2
BLAKE2b-256 91adafbcb247ff2059c8ecdee4b8fda2e7fe8d5122f3c63b89a8a052c4afb954

See more details on using hashes here.

File details

Details for the file telegram_async-3.13.1-py3-none-any.whl.

File metadata

File hashes

Hashes for telegram_async-3.13.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7291d70489395289cad3a2608430cc929d6c7b1a09a534dc06e8cd1449a7906a
MD5 4effee6ecd62037a11fc88da8985c4c8
BLAKE2b-256 3bede7474581748cb8d89b33dc06ed66cc5eb9a71db8b149c3a0668e35696e10

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page