> For the complete documentation index, see [llms.txt](https://pbmodular-docs.gitbook.io/eng-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pbmodular-docs.gitbook.io/eng-docs/extended-usage/callback-functions.md).

# Callback functions

The module has several colback functions that are called as they are initialized:

* `def on_init` - Called after Stage2, due to the peculiarities of asynchronous programming the availability of the database is not guaranteed
* `async def on_db_ready` - Called immediately after full database initialization, useful to use if you need to work with the database immediately after startup

Example usage:

```
async def on_db_ready(self):
    async with self.db.session_maker() as session:
        # load chat states from database
```
