πŸ”₯ Hot ReloadΒΆ

Raito automatically reloads routers on file changes in development mode. This means you can edit handlers and see your updates instantly β€” without restarting.

How it worksΒΆ

  • Hot reload is enabled by default when you set production=False:

    raito = Raito(dispatcher, routers_dir="src/handlers", production=False)
    
  • During raito.setup(), Raito:
    1. Scans your routers_dir for Python files

    2. Skips files starting with _

    3. Dynamically imports all routers (with router = Router(...))

    4. Starts a watchdog using watchfiles.awatch

    5. Tracks file changes and reloads the corresponding routers

  • No need to manually call include_router() or manage imports


ExampleΒΆ

from aiogram import Router
from aiogram.types import Message
from aiogram.filters import Command

router = Router(name="debug")

@router.message(Command("debug"))
async def debug_handler(message: Message):
    await message.answer("Hello, this is a live-reloading handler!")

Edit the message and hit save β€” it will reload automatically.


What happens on file change?ΒΆ

  • If a .py file is modified or created:
    • The corresponding router is unloaded and loaded

  • If a .py file is deleted:
    • The router is unregistered

Each router is uniquely tracked by Router.name.


Telegram Raito CommandsΒΆ

You can also manage routers manually via Telegram chat:

  • .rt routers β€” List all registered routers

  • .rt unload <router_name> β€” Unload a router by name

  • .rt load <router_name> β€” Load a router by name

  • .rt reload <router_name> β€” Reload an existing router


LimitationsΒΆ

  • Changes to shared modules (e.g. utils/, models/) do not trigger reloads

  • Reloads affect only files in routers_dir

  • If a router has side-effects at the top level (e.g., DB queries) β€” they may run twice