Skip to main content

MiniGram 🤖📬

MiniGram is an ultraminimalistic Python library for building Telegram bots that's perfect for use in restricted environments like AWS Lambdas. Say goodbye to bloated libraries and hello to MiniGram's sleek and efficient design! 🚀✨

Features 🌟

  • Lightweight and minimalistic 🍃
  • Works in both synchronous and asynchronous modes ⚡️
  • Seamless integration with popular web libraries like Starlette/FastAPI and aiohttp 🌐
  • Easy to use and understand API 😊
  • Perfect for deploying bots in restricted environments like AWS Lambdas 🔒

Installation 📦

To start building your super cool Telegram bot with MiniGram, simply install it using pip:

pip install minigram-py

Usage 🚀

Using MiniGram is as easy as 1-2-3! Here are a few examples to get you started:

Basic Example

from minigram import MiniGram

YOUR_BOT_TOKEN = "0:0"
CHAT_ID = 0


class MyAwesomeBot(MiniGram):
    def handle_update(self, update):
        match update.update_type:
            case "message":
                match update.text:
                    case "/sync" | "/async":
                        self.reply(update, "I'm a bot, for sure! ⚙️")
                    case _:
                        self.send_text(
                            update.from_id,
                            f"I don't understand that command. 😕\n"
                            f"But your id = {update.from_id}",
                        )

            case "message_reaction":
                self.reply(update, "I see you like this message!")

            case "edited_message":
                self.set_message_reaction(update, "👀")


bot = MyAwesomeBot(YOUR_BOT_TOKEN)
bot.send_text(CHAT_ID, "Hello from an bot! 🚀")
bot.start_polling()

In just a few lines of code, you've created a bot that responds to the "/start" command. How cool is that? 😎

Starlette Integration

from starlette.applications import Starlette
from starlette.routing import Route
from minigram import StarletteMiniGram

YOUR_BOT_TOKEN = "0:0"

class MyStarletteBot(StarletteMiniGram):
    async def incoming(self, msg):
        if msg.text == "/hello":
            return msg.reply("Hello from Starlette! 👋")

bot = MyStarletteBot(YOUR_BOT_TOKEN)
bot.set_webhook("https://yourwebsite.com/webhook")

app = Starlette(debug=True, routes=[
    Route("/webhook", bot.starlette_handler, methods=["POST"]),
])

This example shows how seamlessly MiniGram integrates with Starlette, allowing you to create a webhook endpoint for your bot in no time! 🌐

FastAPI Integration

from fastapi import FastAPI, Request
from minigram import FastAPIMiniGram
from fastapi.responses import JSONResponse

class MyFastAPIBot(FastAPIMiniGram):
    async def incoming(self, msg):
        if msg.text == "/hello":
            return await msg.reply("Hello from FastAPI! 👋")

bot = MyFastAPIBot("YOUR_BOT_TOKEN")
bot.set_webhook("https://yourwebsite.com/webhook")

app = FastAPI()

@app.post("/webhook")
async def webhook(request: Request):
    return await bot.fastapi_handler(request)

MiniGram supports both asynchronous and synchronous methods for FastAPI, giving you the flexibility to choose the best approach for your application. Whether you prefer async or sync, MiniGram has got you covered! 🌐

Asynchronous Mode

import asyncio
from minigram import AsyncMiniGram

YOUR_BOT_TOKEN = "0:0"
CHAT_ID = 0

class MyAsyncBot(AsyncMiniGram):
    async def handle_update(self, update):
        match update.update_type:
            case "message":
                match update.text:
                    case "/sync" | "/async":
                        await self.reply(update, "I'm a asynchronous bot, for sure! ⚙️")
                    case _:
                        await self.send_text(
                            update.from_id,
                            f"I don't understand that command. 😕\n"
                            f"But your id = {update.from_id}",
                        )

            case "message_reaction":
                await self.reply(update, "I see you like this message!")

            case "edited_message":
                await self.set_message_reaction(update, "👀")


async def main():
    bot = MyAsyncBot(YOUR_BOT_TOKEN)
    await bot.send_text(CHAT_ID, "Hello from an asynchronous bot! 🚀")
    await bot.start_polling()


if __name__ == "__main__":
    asyncio.run(main())

MiniGram works just as well in asynchronous mode, making it easy to integrate with your existing async application. 🎛️

Contributing 🤝

We love contributions! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request on our GitHub repository. Let's make MiniGram even better together! 💪

License 📄

MiniGram is released under the MIT License, so feel free to use it in your projects, whether they're open-source or commercial. 😄


Now go forth and build some amazing bots with MiniGram! 🎈🤖

Metadata

Release files for minigram-py 0.5.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 minigram-py 0.5.0
File Size Uploaded Provenance Actions
minigram_py-0.5.0.tar.gz 9.0 kB Without provenance Details for minigram_py-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for minigram-py 0.5.0
File Interpreter ABI Platform Actions
minigram_py-0.5.0-py3-none-any.whl Python 3 none any Details for minigram_py-0.5.0-py3-none-any.whl

Total release size: 18.5 kB

Release files / minigram_py-0.5.0.tar.gz

Download URL minigram_py-0.5.0.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f52c34bbea9f9d1e7d81e64907d28116379a4015b00376b9298032d97f7204a9
BLAKE2b-256 checksum
How to use checksums
2894b5743175be2128fdccd50be73adaceb3f7d409ea6a68bc997a011c06d9f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Release files / minigram_py-0.5.0-py3-none-any.whl

Download URL minigram_py-0.5.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1fcf0a4b65b931c6c4964f9650e032e9921994acae63324518de86ef7fb41034
BLAKE2b-256 checksum
How to use checksums
6704d135d0246eb7e5c2fb285334d8183b8c351fb8bd44608269d20fbfac92b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Security for minigram-py 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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