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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

telegram_async-3.11.4-py3-none-any.whl (140.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for telegram_async-3.11.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fbfa8fc02b5cb71d72c8ad7fa30691691c6e6887032ffccbacb58777325c01f2
MD5 0c860d7b4268baec88521ee2b1038925
BLAKE2b-256 8b5e60c8cf120b829c7aba6ace9badca926263b1c1e5e74b5688c124b88d0928

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