minigram-py


Nameminigram-py JSON
Version 0.5.0 PyPI version JSON
download
home_pageNone
Summaryminimalistic telegram bot framework that can be used in AWS Lambda or anywhere
upload_time2025-01-03 19:38:13
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```python
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

```python
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

```python
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

```python
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](https://github.com/bobuk/minigram-py). Let's make MiniGram even better together! 💪

## License 📄

MiniGram is released under the [MIT License](https://opensource.org/licenses/MIT), 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! 🎈🤖

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "minigram-py",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Grigory Bakunov <bobuk@rubedo.cloud>",
    "download_url": "https://files.pythonhosted.org/packages/28/94/b5743175be2128fdccd50be73adaceb3f7d409ea6a68bc997a011c06d9f6/minigram_py-0.5.0.tar.gz",
    "platform": null,
    "description": "# MiniGram \ud83e\udd16\ud83d\udcec\n\nMiniGram 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! \ud83d\ude80\u2728\n\n## Features \ud83c\udf1f\n\n-   Lightweight and minimalistic \ud83c\udf43\n-   Works in both synchronous and asynchronous modes \u26a1\ufe0f\n-   Seamless integration with popular web libraries like Starlette/FastAPI and aiohttp \ud83c\udf10\n-   Easy to use and understand API \ud83d\ude0a\n-   Perfect for deploying bots in restricted environments like AWS Lambdas \ud83d\udd12\n\n## Installation \ud83d\udce6\n\nTo start building your super cool Telegram bot with MiniGram, simply install it using pip:\n\n```\npip install minigram-py\n```\n\n## Usage \ud83d\ude80\n\nUsing MiniGram is as easy as 1-2-3! Here are a few examples to get you started:\n\n### Basic Example\n\n```python\nfrom minigram import MiniGram\n\nYOUR_BOT_TOKEN = \"0:0\"\nCHAT_ID = 0\n\n\nclass MyAwesomeBot(MiniGram):\n    def handle_update(self, update):\n        match update.update_type:\n            case \"message\":\n                match update.text:\n                    case \"/sync\" | \"/async\":\n                        self.reply(update, \"I'm a bot, for sure! \u2699\ufe0f\")\n                    case _:\n                        self.send_text(\n                            update.from_id,\n                            f\"I don't understand that command. \ud83d\ude15\\n\"\n                            f\"But your id = {update.from_id}\",\n                        )\n\n            case \"message_reaction\":\n                self.reply(update, \"I see you like this message!\")\n\n            case \"edited_message\":\n                self.set_message_reaction(update, \"\ud83d\udc40\")\n\n\nbot = MyAwesomeBot(YOUR_BOT_TOKEN)\nbot.send_text(CHAT_ID, \"Hello from an bot! \ud83d\ude80\")\nbot.start_polling()\n\n```\n\nIn just a few lines of code, you've created a bot that responds to the \"/start\" command. How cool is that? \ud83d\ude0e\n\n### Starlette Integration\n\n```python\nfrom starlette.applications import Starlette\nfrom starlette.routing import Route\nfrom minigram import StarletteMiniGram\n\nYOUR_BOT_TOKEN = \"0:0\"\n\nclass MyStarletteBot(StarletteMiniGram):\n    async def incoming(self, msg):\n        if msg.text == \"/hello\":\n            return msg.reply(\"Hello from Starlette! \ud83d\udc4b\")\n\nbot = MyStarletteBot(YOUR_BOT_TOKEN)\nbot.set_webhook(\"https://yourwebsite.com/webhook\")\n\napp = Starlette(debug=True, routes=[\n    Route(\"/webhook\", bot.starlette_handler, methods=[\"POST\"]),\n])\n```\n\nThis example shows how seamlessly MiniGram integrates with Starlette, allowing you to create a webhook endpoint for your bot in no time! \ud83c\udf10\n\n### FastAPI Integration\n\n```python\nfrom fastapi import FastAPI, Request\nfrom minigram import FastAPIMiniGram\nfrom fastapi.responses import JSONResponse\n\nclass MyFastAPIBot(FastAPIMiniGram):\n    async def incoming(self, msg):\n        if msg.text == \"/hello\":\n            return await msg.reply(\"Hello from FastAPI! \ud83d\udc4b\")\n\nbot = MyFastAPIBot(\"YOUR_BOT_TOKEN\")\nbot.set_webhook(\"https://yourwebsite.com/webhook\")\n\napp = FastAPI()\n\n@app.post(\"/webhook\")\nasync def webhook(request: Request):\n    return await bot.fastapi_handler(request)\n```\n\nMiniGram 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! \ud83c\udf10\n\n\n\n### Asynchronous Mode\n\n```python\nimport asyncio\nfrom minigram import AsyncMiniGram\n\nYOUR_BOT_TOKEN = \"0:0\"\nCHAT_ID = 0\n\nclass MyAsyncBot(AsyncMiniGram):\n    async def handle_update(self, update):\n        match update.update_type:\n            case \"message\":\n                match update.text:\n                    case \"/sync\" | \"/async\":\n                        await self.reply(update, \"I'm a asynchronous bot, for sure! \u2699\ufe0f\")\n                    case _:\n                        await self.send_text(\n                            update.from_id,\n                            f\"I don't understand that command. \ud83d\ude15\\n\"\n                            f\"But your id = {update.from_id}\",\n                        )\n\n            case \"message_reaction\":\n                await self.reply(update, \"I see you like this message!\")\n\n            case \"edited_message\":\n                await self.set_message_reaction(update, \"\ud83d\udc40\")\n\n\nasync def main():\n    bot = MyAsyncBot(YOUR_BOT_TOKEN)\n    await bot.send_text(CHAT_ID, \"Hello from an asynchronous bot! \ud83d\ude80\")\n    await bot.start_polling()\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\nMiniGram works just as well in asynchronous mode, making it easy to integrate with your existing async application. \ud83c\udf9b\ufe0f\n\n## Contributing \ud83e\udd1d\n\nWe love contributions! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request on our [GitHub repository](https://github.com/bobuk/minigram-py). Let's make MiniGram even better together! \ud83d\udcaa\n\n## License \ud83d\udcc4\n\nMiniGram is released under the [MIT License](https://opensource.org/licenses/MIT), so feel free to use it in your projects, whether they're open-source or commercial. \ud83d\ude04\n\n---\n\nNow go forth and build some amazing bots with MiniGram! \ud83c\udf88\ud83e\udd16\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "minimalistic telegram bot framework that can be used in AWS Lambda or anywhere",
    "version": "0.5.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6704d135d0246eb7e5c2fb285334d8183b8c351fb8bd44608269d20fbfac92b0",
                "md5": "991feb14d2f57d15c2441d36a962e1ff",
                "sha256": "1fcf0a4b65b931c6c4964f9650e032e9921994acae63324518de86ef7fb41034"
            },
            "downloads": -1,
            "filename": "minigram_py-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "991feb14d2f57d15c2441d36a962e1ff",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 9530,
            "upload_time": "2025-01-03T19:38:10",
            "upload_time_iso_8601": "2025-01-03T19:38:10.992579Z",
            "url": "https://files.pythonhosted.org/packages/67/04/d135d0246eb7e5c2fb285334d8183b8c351fb8bd44608269d20fbfac92b0/minigram_py-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2894b5743175be2128fdccd50be73adaceb3f7d409ea6a68bc997a011c06d9f6",
                "md5": "f3c830fd0df026d985e6e2a695b61ea7",
                "sha256": "f52c34bbea9f9d1e7d81e64907d28116379a4015b00376b9298032d97f7204a9"
            },
            "downloads": -1,
            "filename": "minigram_py-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f3c830fd0df026d985e6e2a695b61ea7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 8954,
            "upload_time": "2025-01-03T19:38:13",
            "upload_time_iso_8601": "2025-01-03T19:38:13.254408Z",
            "url": "https://files.pythonhosted.org/packages/28/94/b5743175be2128fdccd50be73adaceb3f7d409ea6a68bc997a011c06d9f6/minigram_py-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-03 19:38:13",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "minigram-py"
}
        
Elapsed time: 9.14253s