Skip to main content

Installation | Python

Create internal apps directly in your Python codebase with the Compose SDK. This guide will get you started with two starter apps in ~3 minutes.

1. Install the SDK

Use your package manager to install the Compose SDK.

pip install compose-sdk
# or
poetry add compose-sdk
# or
uv add compose-sdk

2. Add starter apps

Create a new file in your project where you'll add your Compose apps, e.g. compose.py, and paste the following code:

import compose_sdk as c

# For demo purposes. In a real app, you'd use your actual database.
db_users = [
{ "name": "John Doe", "email": "john@doe.com" },
{ "name": "Jane Smith", "email": "jane@smith.com" },
]

def view_users_handler(page: c.Page, ui: c.UI):
page.add(lambda: ui.header("View Users", size="lg"))
users = [*db_users] # fake database call
page.add(lambda: ui.table("users-table", users))

def create_user_handler(page: c.Page, ui: c.UI):
def on_submit(form):
db_users.append({ "name": form["name"], "email": form["email"] })
page.toast("User created successfully", appearance="success")
page.link("view-users")

page.add(lambda: ui.header("Create User", size="lg"))
page.add(lambda: ui.form(
"create-user-form",
[
ui.text_input("name"),
ui.email_input("email")
],
on_submit=on_submit
))

nav = c.Navigation(["view-users", "create-user"])

compose_client = c.Client(
api_key="API_KEY_HERE",
apps=[
c.App(route="view-users", nav=nav, handler=view_users_handler),
c.App(route="create-user", nav=nav, handler=create_user_handler)
]
)

3. Start the Compose Client

In the main entry point of your project, e.g. main.py, add the following:

from .compose import compose_client

# ... other code ...

# Run the client in a background thread. Use .connect() to run the client
# as a blocking process in the main thread.
compose_client.connect_async()
connect_async vs connect

The Python SDK provides two methods to connect to the Compose web dashboard: connect_async and connect.

  • connect_async starts the WebSocket connection in a separate background thread. Use this in environments like Django, Flask, etc. where blocking the main thread would interfere with request handling.
  • connect runs the connection in the main thread. Use this when running a standalone Python process dedicated to Compose apps.

4. Run your app

Run your project's dev server. Compose will automatically connect in the background.

python main.py

You should see your apps come online in the Compose web dashboard.

Next steps

  1. Replace db_users with real database calls.
  2. Go through Compose's core concepts to quickly become productive with the SDK.
  3. Join the Discord community to ask questions and talk to the core team.