{"id":27603531,"url":"https://github.com/taskiq-python/taskiq-aiogram","last_synced_at":"2025-04-22T19:17:19.105Z","repository":{"id":164989025,"uuid":"640389928","full_name":"taskiq-python/taskiq-aiogram","owner":"taskiq-python","description":"Taskiq integration with Aiogram","archived":false,"fork":false,"pushed_at":"2023-09-10T10:36:00.000Z","size":153,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-29T14:22:14.329Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/taskiq-python.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-05-13T23:28:52.000Z","updated_at":"2024-07-30T00:03:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"bb1edb9a-a775-4bab-91b5-d3924459ac7b","html_url":"https://github.com/taskiq-python/taskiq-aiogram","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"d6b65f82d7b785d90b57c985bc5c948665e1a50f"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taskiq-python%2Ftaskiq-aiogram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taskiq-python%2Ftaskiq-aiogram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taskiq-python%2Ftaskiq-aiogram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taskiq-python%2Ftaskiq-aiogram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taskiq-python","download_url":"https://codeload.github.com/taskiq-python/taskiq-aiogram/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247342789,"owners_count":20923655,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-22T19:17:18.475Z","updated_at":"2025-04-22T19:17:19.095Z","avatar_url":"https://github.com/taskiq-python.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Taskiq + Aiogram\n\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/taskiq-aiogram?style=for-the-badge)](https://pypi.org/project/taskiq-aiogram/)\n[![PyPI](https://img.shields.io/pypi/v/taskiq-aiogram?style=for-the-badge)](https://pypi.org/project/taskiq-aiogram/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/taskiq-aiogram?style=for-the-badge)](https://pypistats.org/packages/taskiq-aiogram)\n\nThis repo adds integration between your aiogram application and taskiq.\n\nIt runs all startup and shutdown events of your application and adds 3 dependencies,\nthat you can use in your tasks.\n\n1. `Dispatcher` - that were used along with executor;\n2. `Bot` - your main bot instance;\n3. `List[Bot]` - all your bots.\n\n## Usage\n\nDefine startup and shutdown events for your dispatcher.\nWe use events, because we need to identify what your bot\nwants to do on startup and shutdown.\n\nAlso, it's useful for bot developers to distinct buisness logic\nfrom startup of the bot.\n\nBelow you'll find an example, how to integrate taskiq with your favorite\nbot framework.\n\n```python\nimport asyncio\nimport logging\nimport sys\n\nfrom aiogram import Bot, Dispatcher\n\n# Your taskiq broker\nfrom your_project.tkq import broker\n\ndp = Dispatcher()\nbot = Bot(token=\"TOKEN\")\nbot2 = Bot(token=\"TOKEN\")\n\n\n@dp.startup()\nasync def setup_taskiq(bot: Bot, *_args, **_kwargs):\n    # Here we check if it's a clien-side,\n    # Becuase otherwise you're going to\n    # create infinite loop of startup events.\n    if not broker.is_worker_process:\n        logging.info(\"Setting up taskiq\")\n        await broker.startup()\n\n\n@dp.shutdown()\nasync def shutdown_taskiq(bot: Bot, *_args, **_kwargs):\n    if not broker.is_worker_process:\n        logging.info(\"Shutting down taskiq\")\n        await broker.shutdown()\n\n\nasync def main():\n    await dp.start_polling(bot, bot2)\n\n\nif __name__ == \"__main__\":\n    logging.basicConfig(level=logging.INFO, stream=sys.stdout)\n    asyncio.run(main())\n\n```\n\nThe only thing that left is to add few lines to your broker definition.\n\n\n```python\n# Please use real broker for taskiq.\nfrom taskiq_broker import MyBroker\nimport taskiq_aiogram\n\nbroker = MyBroker()\n\n# This line is going to initialize everything.\ntaskiq_aiogram.init(\n    broker,\n    \"your_project.__main__:dp\",\n    \"your_project.__main__:bot\",\n    \"your_project.__main__:bot2\",\n)\n```\n\nThat's it.\n\nLet's create some tasks! I created task in a separate module,\nnamed `tasks.py`.\n\n```python\nfrom aiogram import Bot\nfrom your_project.tkq import broker\n\n@broker.task(task_name=\"my_task\")\nasync def my_task(chat_id: int, bot: Bot = TaskiqDepends()) -\u003e None:\n    print(\"I'm a task\")\n    await asyncio.sleep(4)\n    await bot.send_message(chat_id, \"task completed\")\n\n```\n\nNow let's call our new task somewhere in bot commands.\n\n```python\nfrom aiogram import types\nfrom aiogram.filters import Command\n\nfrom tasks import my_task\n\n\n@dp.message(Command(\"task\"))\nasync def message(message: types.Message):\n    await my_task.kiq(message.chat.id)\n\n```\n\nTo start the worker, please type:\n\n```\ntaskiq worker your_project.tkq:broker --fs-discover\n```\n\nWe use `--fs-discover` to find all tasks.py modules recursively\nand import all tasks into broker.\n\n\nNow we can fire the task and see everything in action.\n\n![Showcase.jpg](https://raw.githubusercontent.com/taskiq-python/taskiq-aiogram/master/imgs/showcase.jpg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaskiq-python%2Ftaskiq-aiogram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaskiq-python%2Ftaskiq-aiogram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaskiq-python%2Ftaskiq-aiogram/lists"}