v0.3.x · pyrogram_patch
Patching Setup
patch() wraps an existing pyrogram.Client with routing, FSM, and middleware capabilities. It returns a PatchManager through which you register routers and middleware.
patch()
from pyrogram import Client
from pyrogram_patch import patch
from pyrogram_patch.fsm.storages import MemoryStorage
app = Client("my_bot", bot_token="TOKEN")
manager = patch(app, storage=MemoryStorage())
# Register routers before run()
manager.include_router(router)
app.run()| Parameter | Type | Description |
|---|---|---|
client | Client | The pyrogram Client to patch |
storage | BaseStorage | FSM storage backend (default: MemoryStorage) |
PatchManager
The object returned by patch(). Used to wire up routers and middleware.
# Include routers
manager.include_router(router)
manager.include_router(admin_router)
# Add middleware (must be called after app.start())
async def setup():
await app.start()
await manager.add_middleware(my_middleware, kind="before")unpatch()
from pyrogram_patch import unpatch
# Remove all patches from the client
unpatch(app)Note: In v0.5.0 both patch() and unpatch() emitDeprecationWarning. Use KurigramClient in v0.4+.