API Reference¶
This comprehensive API reference covers all classes, methods, and functions available in Flet-Easy. Use this as your complete guide for building applications with Flet-Easy.
Core Classes¶
FletEasy¶
flet_easy.FletEasy¶
Main application class for Flet-Easy.
Configure the app with:
route_prefix: Route prefix different from/.route_init: Initial route, default is/.route_login: Route for redirect when using protected routes.on_keyboard: Enable on_keyboard event (default: False).on_resize: Enable on_resize event (default: False).secret_key: Configure JWT or client storage withSecretKey.auto_logout: Auto-logout with JWT expiry (default: False).path_views: Folder path for auto-discovered page files.logger: Enable logger (default: False).
Example:
import flet as ft
import flet_easy as fs
app = fs.FletEasy(
route_prefix="/FletEasy",
route_init="/FletEasy/home",
)
@app.page("/home", title="Home", page_clear=True)
async def index_page(data: fs.Datasy):
return ft.View(
data.route_init,
controls=[ft.Text("Home", size=40)],
)
app.run()
Source code in src/flet_easy/core/app.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
__init__(route_prefix=None, route_init='/', route_login=None, on_resize=False, on_keyboard=False, secret_key=None, auto_logout=False, path_views=None, logger=False)¶
Source code in src/flet_easy/core/app.py
page(route, title=None, index=None, page_clear=False, share_data=False, protected_route=False, custom_params=None, middleware=None, cache=False)classmethod¶
Decorator to add a new page to the app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route | str | URL path, e.g. | required |
title | Optional[str] | Page title (optional). | None |
index | Optional[int] | Page index for NavigationBar (optional). | None |
page_clear | bool | Remove previous views (optional). | False |
share_data | bool | Share data between pages (optional). | False |
protected_route | bool | Protect with login (optional). | False |
custom_params | Optional[Dict[str, Any]] | Custom URL parameter validators (optional). | None |
middleware | Optional[Union[List[Union[MiddlewareHandler, MiddlewareRequest]], MiddlewareHandler, MiddlewareRequest]] | Page-level middleware (optional). | None |
cache | bool | Preserve page state when navigating (optional). | False |
Source code in src/flet_easy/core/app.py
view(func)¶
Decorator to add custom view controls (appbar, navigation, etc).
The decorated function receives data:fs.Datasy and returns fs.Viewsy.
Source code in src/flet_easy/core/app.py
login(func)¶
Decorator to add login configuration for protected routes.
The decorated function receives data:fs.Datasy and must return a boolean.
Source code in src/flet_easy/core/app.py
config_event_handler(func)¶
Decorator to add page event handler settings.
See: https://flet.dev/docs/controls/page#events
Source code in src/flet_easy/core/app.py
run(name='', host=None, port=0, view=AppView.FLET_APP, assets_dir='assets', upload_dir=None, web_renderer=WebRenderer.CANVAS_KIT, route_url_strategy='path', export_asgi_app=False, fastapi=False, **kwargs)¶
Execute the app. Supports async, fastapi, and export_asgi_app.
Source code in src/flet_easy/core/app.py
add_pages(group_pages)¶
Add pages from other files.
Example:
Source code in src/flet_easy/core/app.py
Quick Reference:
import flet_easy as fs
app = fs.FletEasy(
route_prefix="/app",
route_init="/app/home",
route_login="/app/login",
on_keyboard=True,
on_resize=True,
secret_key=fs.SecretKey("your-key"),
auto_logout=True,
logger=True
)
@app.page("/home")
def home_page(data: fs.Datasy):
return ft.View("/home", controls=[...])
app.run()
Datasy¶
flet_easy.Datasy¶
Bases: AuthMixin
The decorated function will always receive a parameter which is data (can be any name), which will make an object of type Datasy of Flet-Easy.
This class has the following attributes, in order to access its data:
page: We get the values of the page provided byFlet.url_params: We obtain a dictionary with the values passed through the url.view: Get aViewobject fromFlet, previously configured with theviewdecorator ofFlet-Easy.route_prefix: Value entered in theFletEasyclass parameters to create the app object.route_init: Value entered in theFletEasyclass parameters to create the app object.route_login: Value entered in theFletEasyclass parameters to create the app object.
share: It is used to be able to store and to obtain values in the client session.on_keyboard_event: get event values to use in the page.on_resize: get event values to use in the page.logout: method to close sessions of all sections in the browser (client storage).login: method to create sessions of all sections in the browser (client storage).go/go_route: Method to change the application path.go_back: Method to go back to the previous route.go_navigation_bar: Handles navigation bar changes.history_routes: Get the history of the routes.route: Route provided by the route event.redirect: To redirect to a path before the page loads, it is used in middleware.page_reload: Use this method to reload the page.dynamic_control: Adds dynamic control to the page.confirm_pop: Confirm pop view.
Source code in src/flet_easy/core/data.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
pagepropertywritable¶
url_paramspropertywritable¶
viewpropertywritable¶
route_prefixpropertywritable¶
route_initpropertywritable¶
route_loginpropertywritable¶
shareproperty¶
on_keyboard_eventpropertywritable¶
on_resizepropertywritable¶
history_routesproperty¶
routepropertywritable¶
go(route)¶
To change the application path, it is important for better validation to avoid using page.go().
go_back(e=None)¶
Go back to the previous route.
Source code in src/flet_easy/core/data.py
go_navigation_bar(e)¶
Handles navigation bar changes. Use this method in the on_change event of 'ft.NavigationBar' or 'ft.CupertinoNavigationBar' controls.
Source code in src/flet_easy/core/data.py
Quick Reference:
def my_page(data: fs.Datasy):
# Navigation
data.go("/other-page")
data.go_back()
# Authentication
data.login("token", "jwt-value")
data.logout("token", next_route="/login")
# JWT decoding (replaces fs.decode / fs.decode_async)
decoded = data.decode_jwt("token") # sync
# decoded = await data.decode_jwt_async("token") # async
# Data sharing
data.share.set("key", "value")
value = data.share.get("key")
# Page access
data.page.title = "New Title"
data.page.update()
Pagesy¶
flet_easy.Pagesy¶
To add pages, it requires the following parameters: * route: text string of the url, for example('/task'). * view: Stores the page function. * title : Define the title of the page. * index : Define the index of the page, use in controls like ft.NavigationBar and ft.CupertinoNavigationBar. * clear: Removes the pages from the page.views list of flet. (optional) * share_data : It is a boolean value, which is useful if you want to share data between pages, in a more restricted way. (optional) * protected_route: Protects the route of the page, according to the configuration of the login decorator of the FletEasy class. (optional) * custom_params: To add validation of parameters in the custom url using a list, where the key is the name of the parameter validation and the value is the custom function that must report a boolean value. * middleware : It acts as an intermediary between different software components, intercepting and processing requests and responses. They allow adding functionalities to an application in a flexible and modular way. (optional) * cache: Boolean that preserves page state when navigating. Controls retain their values instead of resetting. (Optional)
Example:
Source code in src/flet_easy/core/pages.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
__init__(route, view, title=None, index=None, clear=False, share_data=False, protected_route=False, custom_params=None, middleware=None, cache=False)¶
Source code in src/flet_easy/core/pages.py
Quick Reference:
from flet_easy import Pagesy
page = Pagesy(
route="/user/{id:d}",
view=user_view_function,
title="User Profile",
protected_route=True,
middleware=[auth_middleware],
cache=True,
share_data=True
)
AddPagesy¶
flet_easy.AddPagesy¶
This class allows you to add pages from other files to the main Flet-Easy class.
Requiere los parámetros: - route_prefix: cadena de texto que se unira a la url del decorator page, ejemplo(/users) esto englobara todas las urls de esta clase. (opcional) - middleware: lista de middlewares que se agregaran a la página. (opcional)
Ejemplo:
users = fs.AddPagesy(route_prefix="/user")
@users.page("/task")
async def task_page(data: fs.Datasy):
page = data.page
page.title = "Task"
return ft.View(
route="/users/task",
controls=[ft.Text("Task")],
)
Source code in src/flet_easy/core/pages.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
__build_route(route)¶
page(route, title=None, index=None, page_clear=False, share_data=False, protected_route=False, custom_params=None, middleware=None, cache=False)¶
Decorator for adding pages with configuration.
Source code in src/flet_easy/core/pages.py
Quick Reference:
from flet_easy import AddPagesy, Pagesy
pages = AddPagesy([
Pagesy("/home", home_view),
Pagesy("/about", about_view),
Pagesy("/contact", contact_view)
])
app.add_pages(pages)
Viewsy¶
flet_easy.Viewsy¶
Quick Reference:
from flet_easy import Viewsy
import flet as ft
@app.view
def main_view(data: fs.Datasy):
return Viewsy(
appbar=ft.AppBar(title=ft.Text("My App")),
drawer=ft.NavigationDrawer(...),
bgcolor=ft.Colors.GREY_50,
padding=ft.padding.all(20)
)
Authentication & Security¶
SecretKey¶
flet_easy.SecretKeydataclass¶
Correctly add the secret key in the FletEasy class parameter.
EasyKey¶
flet_easy.EasyKey¶
To obtain a secret_key more easily, support algorithms [ HS256, RS256 ]
Example:¶
import flet_easy as fs
key = fs.EasyKey()
# --- HS256
SECRET_KEY = key.secret_key()
# --- RS256
PRIVATE_KEY = key.private_key()
PUBLIC_KEY = key.public_key()
Source code in src/flet_easy/security/jwt.py
Quick Reference:
from flet_easy import EasyKey, SecretKey
# Generate keys
key_gen = EasyKey()
secret = key_gen.secret_key() # For HS256
private_key = key_gen.private_key() # For RS256
public_key = key_gen.public_key() # For RS256
# Use with FletEasy
app = fs.FletEasy(secret_key=SecretKey(secret))
JWT Functions¶
[!warning] Deprecated since v0.4.0
fs.decode()andfs.decode_async()are deprecated. Usedata.decode_jwt()/data.decode_jwt_async()(methods onDatasy) instead.
flet_easy.Datasy.decode_jwt(key)¶
Decode JWT
Parameters¶
- key: Key to store the value used in the
loginmethod ofDatasy.
Source code in src/flet_easy/security/auth.py
flet_easy.Datasy.decode_jwt_async(key_login)async¶
Decode JWT asynchronously
Parameters¶
- key: Key to store the value used in the
loginmethod ofDatasy.
Source code in src/flet_easy/security/auth.py
flet_easy.decode(key_login, data)¶
decodes the jwt and updates the browser sessions.
Parameters to use:¶
key_login: key used to store data in the client, also used in theloginmethod ofDatasy.data: Instance object of theDatasyclass.
Source code in src/flet_easy/security/jwt.py
flet_easy.decode_async(key_login, data)async¶
"decodes the jwt and updates the browser sessions.
Parameters to use:¶
key_login: key used to store data in the client, also used in theloginmethod ofDatasy.data: Instance object of theDatasyclass.
Source code in src/flet_easy/security/jwt.py
flet_easy.encode_HS256(payload, secret_key, time_expiry=None)¶
flet_easy.encode_RS256(payload, private, time_expiry=None)¶
Quick Reference:
from flet_easy import SecretKey
import flet_easy as fs
# --- New API (v0.4.0+) ---
@app.login
async def login_required(data: fs.Datasy) -> bool:
return await data.decode_jwt_async(key_login="login")
# --- Deprecated (will be removed) ---
# value = fs.decode(key_login="login", data=data)
Event Handling¶
Keyboardsy¶
flet_easy.Keyboardsy¶
Class that manages keyboard input values.
Source code in src/flet_easy/ui/controls.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
Quick Reference:
@app.config_event_handler
def handle_events(data: fs.Datasy):
if data.on_keyboard_event:
key = data.on_keyboard_event.key()
if key == "Escape":
data.go("/home")
elif key == "F1":
data.go("/help")
Resizesy¶
flet_easy.Resizesy¶
For the manipulation of the on_resize event of flet.
Source code in src/flet_easy/ui/controls.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
Quick Reference:
@app.config_event_handler
def handle_events(data: fs.Datasy):
if data.on_resize:
width = data.on_resize.width()
height = data.on_resize.height()
# Responsive layout adjustments
if width < 600:
# Mobile layout
pass
else:
# Desktop layout
pass
Responsive Design¶
ResponsiveControlsy¶
flet_easy.ResponsiveControlsy¶
Bases: Canvas
Allows the controls to adapt to the size of the app (responsive).
Source code in src/flet_easy/ui/controls.py
Quick Reference:
from flet_easy import ResponsiveControlsy
import flet as ft
responsive_text = ResponsiveControlsy(
controls={
"xs": ft.Text("Mobile", size=14),
"sm": ft.Text("Tablet", size=16),
"md": ft.Text("Desktop", size=18),
"lg": ft.Text("Large Desktop", size=20),
}
)
Reference System¶
Ref¶
flet_easy.Ref¶
Bases: Ref[T]
Get the reference of the control used by flet, linked to the created component. Similar to flet, but more reduced by getting the value of the control with (c).
Source code in src/flet_easy/ui/controls.py
Quick Reference:
from flet_easy import Ref
import flet as ft
def my_page(data: fs.Datasy):
text_ref = Ref[ft.TextField]()
def handle_click(_):
value = text_ref.current.value
print(f"Input value: {value}")
return ft.View(
"/page",
controls=[
ft.TextField(ref=text_ref, label="Enter text"),
ft.ElevatedButton("Get Value", on_click=handle_click)
]
)
Middleware System¶
MiddlewareRequest¶
flet_easy.MiddlewareRequest¶
Source code in src/flet_easy/core/middleware.py
Quick Reference:
from flet_easy import MiddlewareRequest, Redirect
class AuthMiddleware(MiddlewareRequest):
def before_request(self):
if not self.data.page.client_storage.get("auth_token"):
return Redirect("/login")
def after_request(self):
# Log the request
print(f"Accessed: {self.data.route}")
@app.page("/protected", middleware=[AuthMiddleware])
def protected_page(data: fs.Datasy):
return ft.View("/protected", controls=[...])
Utility Classes¶
Redirect¶
flet_easy.Redirectdataclass¶
Quick Reference:
from flet_easy import Redirect
def auth_middleware(data: fs.Datasy):
if not data.page.client_storage.get("token"):
return Redirect("/login")
return None
Route Parameter Types¶
Flet-Easy supports several parameter types in dynamic routes:
| Type | Syntax | Description | Example |
|---|---|---|---|
| Integer | {name:d} | Matches integers | /user/{id:d} → /user/123 |
| String | {name:str} | Matches any string | /category/{name:str} → /category/electronics |
| Lowercase | {name:l} | Matches lowercase strings | /tag/{slug:l} → /tag/python-tips |
| Float | {name:f} | Matches floating point numbers | /price/{amount:f} → /price/19.99 |
Example Usage:
@app.page("/blog/{year:d}/{month:d}/{slug:str}")
def blog_post(data: fs.Datasy, year: int, month: int, slug: str):
# year and month are automatically converted to int
# slug remains as string
post = get_blog_post(year, month, slug)
return ft.View(f"/blog/{year}/{month}/{slug}", controls=[...])
Configuration Options¶
FletEasy Configuration¶
| Parameter | Type | Default | Description |
|---|---|---|---|
route_prefix | str | "" | Base prefix for all routes |
route_init | str | "/" | Initial route when app starts |
route_login | str | "/login" | Redirect route for protected pages |
on_keyboard | bool | False | Enable keyboard event handling |
on_resize | bool | False | Enable window resize events |
secret_key | SecretKey | None | Secret key for JWT and encryption |
auto_logout | bool | False | Auto-logout on JWT expiration |
path_views | Path | None | Directory for automatic page discovery |
logger | bool | False | Enable detailed logging |
Pagesy Configuration¶
| Parameter | Type | Default | Description |
|---|---|---|---|
route | str | Required | URL pattern for the page |
view | Callable | Required | Function that returns a View |
title | str | None | Page title for browser |
index | int | None | Navigation index for tabs |
clear | bool | False | Clear navigation history |
share_data | bool | False | Enable data sharing |
protected_route | bool | False | Require authentication |
custom_params | Dict | None | Custom parameter validators |
middleware | List | None | Page-specific middleware |
cache | bool | False | Preserve page state |
Error Handling¶
Common Exceptions¶
from flet_easy.exceptions import (
FletEasyError,
AddPagesError,
LoginError,
LogoutError,
MiddlewareError
)
try:
app = fs.FletEasy()
app.run()
except FletEasyError as e:
print(f"FletEasy error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
Error Handling in Pages¶
@app.page("/api-demo")
def api_demo_page(data: fs.Datasy):
try:
# Your logic here
result = fetch_api_data()
return create_success_view(result)
except Exception as e:
# Show error to user
data.page.show_snack_bar(
ft.SnackBar(content=ft.Text(f"Error: {str(e)}"))
)
# Return error view
return ft.View(
"/api-demo",
controls=[
ft.Text("An error occurred", color=ft.Colors.RED),
ft.ElevatedButton("Retry", on_click=data.go("/api-demo")),
ft.ElevatedButton("Go Home", on_click=data.go("/home"))
]
)
Performance Tips¶
Use Caching Wisely¶
# Cache expensive pages
@app.page("/reports", cache=True)
def reports_page(data: fs.Datasy):
# Expensive computation
return ft.View("/reports", controls=[...])
# Don't cache dynamic content
@app.page("/live-feed", cache=False)
def live_feed_page(data: fs.Datasy):
# Real-time data
return ft.View("/live-feed", controls=[...])
Optimize Page Updates¶
def update_multiple_controls(data: fs.Datasy):
# Batch updates
control1.value = "New Value 1"
control2.value = "New Value 2"
control3.value = "New Value 3"
# Single update call
data.page.update()
Use Lazy Loading¶
@app.page("/heavy-page")
def heavy_page(data: fs.Datasy):
# Load heavy content only when needed
def load_content(_):
heavy_data = load_heavy_data()
content_container.content = create_heavy_ui(heavy_data)
data.page.update()
content_container = ft.Container()
return ft.View(
"/heavy-page",
controls=[
ft.ElevatedButton("Load Content", on_click=load_content),
content_container
]
)
Migration Guide¶
From v0.1.x to v0.2.x¶
Breaking Changes:
update_login→loginlogaut→logout- Function parameters changed for
loginandconfig_event_handlerdecorators
Migration Example:
# Old (v0.1.x)
@app.login
def check_auth(page: ft.Page):
return page.client_storage.get("token") is not None
# New (v0.2.x)
@app.login
def check_auth(data: fs.Datasy):
return data.page.client_storage.get("token") is not None
This API reference provides comprehensive coverage of all Flet-Easy features. For detailed examples and tutorials, refer to the other sections of this documentation.