π₯ 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: Scans your
routers_dirfor Python filesSkips files starting with
_Dynamically imports all routers (with
router = Router(...))Starts a watchdog using
watchfiles.awatchTracks file changes and reloads the corresponding routers
- During
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
.pyfile is modified or created: The corresponding router is unloaded and loaded
- If a
- If a
.pyfile is deleted: The router is unregistered
- If a
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 reloadsReloads affect only files in
routers_dirIf a router has side-effects at the top level (e.g., DB queries) β they may run twice