Skip to main content


If you build a chat app using Flet you need somehow to pass user messages between sessions. When a user sends a message it should be broadcasted to all other app sessions and displayed on their pages.

Flet provides a simple built-in PubSub mechanism for asynchronous communication between page sessions.

Flet PubSub allows broadcasting messages to all app sessions or sending only to specific "topic" (or "channel") subscribers.

A typical PubSub usage would be:

This is an example of a simple chat application:

import flet
from flet import Column, ElevatedButton, Page, Row, Text, TextField

def main(page: Page):
page.title = "Flet Chat"

# subscribe to broadcast messages
def on_message(msg):


def send_click(e):
page.pubsub.send_all(f"{user.value}: {message.value}")
# clean up the form
message.value = ""

messages = Column()
user = TextField(hint_text="Your name", width=150)
message = TextField(hint_text="Your message...", expand=True) # fill all the space
send = ElevatedButton("Send", on_click=send_click)
page.add(messages, Row(controls=[user, message, send])), view=flet.WEB_BROWSER)