Skip to content

Working with other apps

Working with other apps and creating apis

To be able to make our main app work with other apps, besides being able to create apis from the same url path with the same host and port. First we must obtain the main of the app to be able to mount it in another app. For it we are going to use the app.fastapi()

More information

Example

main.py
import flet as ft
import flet_easy as fs
import flet_fastapi

app = fs.FletEasy(
    route_init="/Flet-Easy",
)

@app.page(route="/Flet-Easy")
def home_page(data: fs.Datasy):
    page = data.page
    page.title = "Flet-Easy"

    return ft.View(
        controls=[
            ft.Text(f"Home page: {page.title}"),
            ft.Text(f"Route: {page.route}"),
        ],
        vertical_alignment="center",
        horizontal_alignment="center",
    )

# We create an app in FastApi
app_main = flet_fastapi.FastAPI()

# Creating a basic test api.
@app_main.get("/testing")
def test_api():
    return {"success": True}

# We add the `flet` app to `fastapi`.
app_main.mount("/", flet_fastapi.app(app.fastapi()))

Run the app

uvicorn main:app_main

📷 Demo

app