MCPcopy
hub / github.com/flet-dev/flet / run

Function run

sdk/python/packages/flet/src/flet/app.py:60–139  ·  view source on GitHub ↗

Runs the Flet app. Args: main: Application entry point. Handler (function or coroutine) must have 1 parameter of instance :class:`~flet.Page`. before_main: Called after `Page` is created but before `main`. name: Page/app name used in web URL path when ap

(
    main: AppCallable,
    before_main: Optional[AppCallable] = None,
    name: str = "",
    host: Optional[str] = None,
    port: int = 0,
    view: Optional[AppView] = AppView.FLET_APP,
    assets_dir: Optional[str] = "assets",
    upload_dir: Optional[str] = None,
    web_renderer: WebRenderer = WebRenderer.AUTO,
    route_url_strategy: RouteUrlStrategy = RouteUrlStrategy.PATH,
    no_cdn: Optional[bool] = False,
    export_asgi_app: Optional[bool] = False,
    target=None,
)

Source from the content-addressed store, hash-verified

58
59
60def run(
61 main: AppCallable,
62 before_main: Optional[AppCallable] = None,
63 name: str = "",
64 host: Optional[str] = None,
65 port: int = 0,
66 view: Optional[AppView] = AppView.FLET_APP,
67 assets_dir: Optional[str] = "assets",
68 upload_dir: Optional[str] = None,
69 web_renderer: WebRenderer = WebRenderer.AUTO,
70 route_url_strategy: RouteUrlStrategy = RouteUrlStrategy.PATH,
71 no_cdn: Optional[bool] = False,
72 export_asgi_app: Optional[bool] = False,
73 target=None,
74):
75 """
76 Runs the Flet app.
77
78 Args:
79 main: Application entry point. Handler (function or coroutine) must
80 have 1 parameter of instance :class:`~flet.Page`.
81 before_main: Called after `Page` is created but before `main`.
82 name: Page/app name used in web URL path when applicable.
83 host: Host/IP to bind the web server to.
84 port: TCP port to bind. If `0`, an available port is chosen when needed.
85 view: Preferred app presentation mode.
86 assets_dir: A path to app's assets directory.
87 upload_dir: A path to a directory with uploaded files,
88 or where uploaded files should be saved.
89 web_renderer: The type of web renderer to use.
90 route_url_strategy: The strategy to use for generating URLs.
91 no_cdn: Whether not load CanvasKit, Pyodide, or fonts from CDN.
92 export_asgi_app: If `True`, returns a configured ASGI app instead of
93 running an event loop.
94 target: Deprecated alias for `main`.
95
96 Returns:
97 When `export_asgi_app=True`, returns a FastAPI ASGI app.
98 Otherwise, runs the app and returns `None`.
99 """
100 if is_pyodide():
101 __run_pyodide(main=main or target, before_main=before_main)
102 return
103
104 if export_asgi_app:
105 ensure_flet_web_package_installed()
106 from flet_web.fastapi.serve_fastapi_web_app import get_fastapi_web_app
107
108 return get_fastapi_web_app(
109 main=main or target,
110 before_main=before_main,
111 page_name=__get_page_name(name),
112 assets_dir=__get_assets_dir_path(assets_dir, relative_to_cwd=True),
113 upload_dir=__get_upload_dir_path(upload_dir, relative_to_cwd=True),
114 web_renderer=web_renderer,
115 route_url_strategy=route_url_strategy,
116 no_cdn=no_cdn,
117 )

Callers 1

appFunction · 0.70

Calls 11

is_pyodideFunction · 0.90
get_fastapi_web_appFunction · 0.90
WebRendererClass · 0.90
RouteUrlStrategyClass · 0.90
__run_pyodideFunction · 0.85
__get_page_nameFunction · 0.85
__get_assets_dir_pathFunction · 0.85
__get_upload_dir_pathFunction · 0.85
run_asyncFunction · 0.85
runMethod · 0.45

Tested by

no test coverage detected