aiogram3-di


Nameaiogram3-di JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/Vladyslav49/aiogram3_di
SummaryDependency Injection implementation for aiogram 3.
upload_time2023-12-14 19:45:39
maintainer
docs_urlNone
authorVladyslav Timofeev
requires_python>=3.10
licenseMIT
keywords aiogram telegram bots di dependency injection
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ### Example of usage

```python
import logging
from os import getenv
from typing import Annotated

from aiogram import Router, Bot, Dispatcher
from aiogram.types import Message, User
from aiogram3_di import setup_di, Depends

router = Router()


def get_user_full_name(event_from_user: User) -> str:
    return event_from_user.full_name


@router.message()
async def start(
        message: Message, full_name: Annotated[str, Depends(get_user_full_name)]
) -> None:
    await message.answer(f"Hi {full_name}")


def main() -> None:
    logging.basicConfig(level=logging.INFO)

    bot = Bot(token=getenv("BOT_TOKEN"))

    dp = Dispatcher()

    dp.include_router(router)

    setup_di(dp)

    dp.run_polling(bot)


if __name__ == "__main__":
    main()
```

### Handler Dependencies.

You can use `Depends` in the flags parameter of the handler, for example: 

```python
flags={"dependencies": [Depends(verify_user)]}
```

### Details

It is inspired by [FastAPI](https://github.com/tiangolo/fastapi).

If you define a normal def, your function will be called in a different thread.

### License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Vladyslav49/aiogram3_di",
    "name": "aiogram3-di",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "Aiogram,Telegram,Bots,DI,Dependency Injection",
    "author": "Vladyslav Timofeev",
    "author_email": "Timofeevvladyslav49@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/22/ad/208497a05199e8f87ee594b8b8854c145f57af7b6dd2186758c3a0e870ce/aiogram3_di-2.0.0.tar.gz",
    "platform": null,
    "description": "### Example of usage\n\n```python\nimport logging\nfrom os import getenv\nfrom typing import Annotated\n\nfrom aiogram import Router, Bot, Dispatcher\nfrom aiogram.types import Message, User\nfrom aiogram3_di import setup_di, Depends\n\nrouter = Router()\n\n\ndef get_user_full_name(event_from_user: User) -> str:\n    return event_from_user.full_name\n\n\n@router.message()\nasync def start(\n        message: Message, full_name: Annotated[str, Depends(get_user_full_name)]\n) -> None:\n    await message.answer(f\"Hi {full_name}\")\n\n\ndef main() -> None:\n    logging.basicConfig(level=logging.INFO)\n\n    bot = Bot(token=getenv(\"BOT_TOKEN\"))\n\n    dp = Dispatcher()\n\n    dp.include_router(router)\n\n    setup_di(dp)\n\n    dp.run_polling(bot)\n\n\nif __name__ == \"__main__\":\n    main()\n```\n\n### Handler Dependencies.\n\nYou can use `Depends` in the flags parameter of the handler, for example: \n\n```python\nflags={\"dependencies\": [Depends(verify_user)]}\n```\n\n### Details\n\nIt is inspired by [FastAPI](https://github.com/tiangolo/fastapi).\n\nIf you define a normal def, your function will be called in a different thread.\n\n### License\n\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Dependency Injection implementation for aiogram 3.",
    "version": "2.0.0",
    "project_urls": {
        "Homepage": "https://github.com/Vladyslav49/aiogram3_di",
        "Repository": "https://github.com/Vladyslav49/aiogram3_di"
    },
    "split_keywords": [
        "aiogram",
        "telegram",
        "bots",
        "di",
        "dependency injection"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "100ea7921ebd601734dbe7b7491e637ccea31252ee75966f54c50f0004125c2d",
                "md5": "180170dd6d22102747ca3e377e81a590",
                "sha256": "d91ccddfe26451681ae802f055db2ae71d732cb0711b3ba855ee6e4164bfdd96"
            },
            "downloads": -1,
            "filename": "aiogram3_di-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "180170dd6d22102747ca3e377e81a590",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 6912,
            "upload_time": "2023-12-14T19:45:37",
            "upload_time_iso_8601": "2023-12-14T19:45:37.584302Z",
            "url": "https://files.pythonhosted.org/packages/10/0e/a7921ebd601734dbe7b7491e637ccea31252ee75966f54c50f0004125c2d/aiogram3_di-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "22ad208497a05199e8f87ee594b8b8854c145f57af7b6dd2186758c3a0e870ce",
                "md5": "c4cdc900fa7c4e5ade10e273da4338ec",
                "sha256": "1a510a49dc0df93a65557ce36da0a10ce6c40438f0b329deb05388d0d7b5562f"
            },
            "downloads": -1,
            "filename": "aiogram3_di-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c4cdc900fa7c4e5ade10e273da4338ec",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 5030,
            "upload_time": "2023-12-14T19:45:39",
            "upload_time_iso_8601": "2023-12-14T19:45:39.388258Z",
            "url": "https://files.pythonhosted.org/packages/22/ad/208497a05199e8f87ee594b8b8854c145f57af7b6dd2186758c3a0e870ce/aiogram3_di-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-14 19:45:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Vladyslav49",
    "github_project": "aiogram3_di",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "aiogram3-di"
}
        
Elapsed time: 1.03273s