Skip to main content

aiotg

Asynchronous Python API for building Telegram bots, featuring:

  • Easy and declarative API

  • Hassle-free setup - no need for SSL certificates or static IP

  • Built-in support for analytics via chatbase.com

  • Automatic handling of Telegram API throttling or timeouts

Install it with pip:

pip install aiotg

Then you can create a new bot in few lines:

from aiotg import Bot, Chat

bot = Bot(api_token="...")

@bot.command(r"/echo (.+)")
def echo(chat: Chat, match):
    return chat.reply(match.group(1))

bot.run()

Now run it with a proper API_TOKEN and it should reply to /echo commands.

The example above looks like a normal synchronous code but it actually returns a coroutine. If you want to make an external request (and that’s what bots usually do) just use aiohttp and async/await syntax:

import aiohttp
from aiotg import Bot, Chat

bot = Bot(api_token="...")

@bot.command("bitcoin")
async def bitcoin(chat: Chat, match):
    url = "https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCUSD"
    async with aiohttp.ClientSession() as session:
        response = await session.get(url)
        info = await response.json()
        await chat.send_text(str(info["averages"]["day"]))

bot.run()

But what if you just want to write a quick integration and don’t need to provide a conversational interface? We’ve got you covered! You can send messages (or any other media) by constructing a Chat object with user_id or channel name. We even saved you some extra keystrokes by providing handy Channel constructors:

...
channel = bot.channel("@yourchannel")
private = bot.private("1111111")

async def greeter():
    await channel.send_text("Hello from channel!")
    await private.send_text("Why not greet personally?")
...

Examples

For a real world example, take a look at WhatisBot or Music Catalog Bot.

For more information on how to use the project, see the project’s documentation.

Release files for aiotg 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiotg 2.0.0
File Size Uploaded
aiotg-2.0.0.tar.gz 12.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aiotg 2.0.0
File Interpreter ABI Platform
aiotg-2.0.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 26.0 kB

Release files / aiotg-2.0.0.tar.gz

Download URL aiotg-2.0.0.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9932f117d3faaf10ee6b36c580ffa033d4a3311b0d54dcbd261cb93e8bae3b1e
BLAKE2b-256 checksum
How to use checksums
cfdeed3aaeae5956eb5e2ff98698d07cce0246009ed6654840e45bd376fc4266
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.2

Release files / aiotg-2.0.0-py2.py3-none-any.whl

Download URL aiotg-2.0.0-py2.py3-none-any.whl
Size 13.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
05f7f7cccff9dc25e86d54efbfda862032c08302be41d2d207675a61802ac11e
BLAKE2b-256 checksum
How to use checksums
b483e183c14ac3aa8a5852fc48b56d7872cc904614040f002e023b68a4c960ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.2

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.0

1 release file

0.9.9

1 release file

0.9.8

1 release file

0.9.7

1 release file

0.9.6

1 release file

0.9.5

1 release file

0.9.4

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.9.0

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.22

1 release file

0.7.21

1 release file

0.7.20

1 release file

0.7.19

1 release file

0.7.18

1 release file

0.7.17

1 release file

0.7.16

1 release file

0.7.15

1 release file

0.7.14

1 release file

0.7.13

1 release file

0.7.10

2 release files

0.7.9

2 release files

0.7.8

2 release files

0.7.7

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

3 release files

0.7.1

3 release files

0.7.0

3 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

3 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page