App Model
This is Miniappi's Python package for communicating with Miniappi server.
Miniappi application
This class is the entrypoint to create apps and it handles the communication with Miniappi server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Name of the application. None for anonymous applications. Does nothing currently but exists for forward compatibility. |
None
|
user_context
|
Context
|
Optional extra user scoped context to keep track on user level data. This is automatically scoped and can be set globally. |
None
|
app_context
|
Context
|
Optional app scoped context to keep track on app level data. This is automatically scoped and can be set globally. |
None
|
Examples:
from miniappi import App
app = App()
@app.on_open()
async def new_user(session):
print("New user joined")
...
app.run()
on_start()
Callback for the app starting.
Examples
@app.on_start()
async def app_start():
...
on_open(pass_session=False)
Callback for user opening an app session (user connected to the app)
Examples
@app.on_open()
async def new_user(session):
...
on_message()
Callback for user sending a message (data).
Examples
@app.on_message()
async def new_message(msg):
...
on_close()
Callback for user closing the app session (user left the app).
Examples
@app.on_close()
async def user_left(exc_type, exc, tb):
...
on_end()
Callback for app shutting down.
Examples
@app.on_end()
async def app_shutdown(exc_type, exc, tb):
...
temp()
Temporarily set callbacks to the app
This is useful for syncing other sessions
Examples
async with app.temp() as temp:
@temp.on_open()
async def new_users(session):
...
# Callback "new_users" will called
# now for all new user sessions
...
# Callback "new_users" won't be called
# anymore
...