Skip to main content

Example of usage

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:

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

Details

It is inspired by FastAPI.

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

License

MIT

Metadata

Release files for aiogram3-di 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 aiogram3-di 2.0.0
File Size Uploaded Provenance Actions
aiogram3_di-2.0.0.tar.gz 5.0 kB Without provenance Details for aiogram3_di-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aiogram3-di 2.0.0
File Interpreter ABI Platform Actions
aiogram3_di-2.0.0-py3-none-any.whl Python 3 none any Details for aiogram3_di-2.0.0-py3-none-any.whl

Total release size: 11.9 kB

Release files / aiogram3_di-2.0.0.tar.gz

Download URL aiogram3_di-2.0.0.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1a510a49dc0df93a65557ce36da0a10ce6c40438f0b329deb05388d0d7b5562f
BLAKE2b-256 checksum
How to use checksums
22ad208497a05199e8f87ee594b8b8854c145f57af7b6dd2186758c3a0e870ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.0 CPython/3.10.6 Linux/5.15.0-48-generic

Release files / aiogram3_di-2.0.0-py3-none-any.whl

Download URL aiogram3_di-2.0.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d91ccddfe26451681ae802f055db2ae71d732cb0711b3ba855ee6e4164bfdd96
BLAKE2b-256 checksum
How to use checksums
100ea7921ebd601734dbe7b7491e637ccea31252ee75966f54c50f0004125c2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.0 CPython/3.10.6 Linux/5.15.0-48-generic

Security for aiogram3-di 2.0.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