This comprehensive guide will walk you through the process of adding custom user extensions to your Flet applications. Perfect for beginners who want to extend Flet's functionality with community-created widgets and components.
Before starting, make sure you have:
UV is a fast Python package manager that we'll use for dependency management.
pip install uv
A virtual environment keeps your project dependencies isolated from your system Python.
uv venv
For macOS/Linux:
source .venv/bin/activate
For Windows:
.venv\Scripts\activate
What this does:
.venv
folderHow to know it's active: You'll see (.venv)
at the beginning of your terminal prompt.
Install Flet with all optional dependencies:
uv pip install flet[all]==0.28.3
If you don't have an existing project, create a new one:
uv run flet create test_app
test_app
with your desired project name.
What this does: Creates a new Flet project with the following structure:
test_app/
├── pyproject.toml # Project configuration
├── README.md # Project documentation
├── src/
│ ├── main.py # Main application file
│ └── assets/ # Static files (images, etc.)
cd test_app
Option 1: From project directory (recommended):
uv sync
Option 2: Specify path to project directory:
uv sync --project /path/to/your/project
Examples with absolute paths (full paths):
# If you're already in the project directory (where pyproject.toml is located)
uv sync
# Absolute paths (full paths from root)
uv sync --project /Users/username/Desktop/my_awesome_app
uv sync --project /home/username/projects/flet_app
uv sync --project ~/my_flet_projects/test_app
# On Windows (absolute paths)
uv sync --project C:\Users\username\Desktop\my_awesome_app
uv sync --project "C:\Program Files\MyProjects\flet_app"
Examples with relative paths:
# Relative to current directory
uv sync --project ./my_project
uv sync --project ../parent_folder/my_project
uv sync --project ../../other_projects/flet_app
# Go up one level and into project folder
uv sync --project ../test_app
# Current directory (same as just 'uv sync')
uv sync --project .
What this does:
.venv
folder inside your projectpyproject.toml
uv.lock
Important: uv sync
requires a pyproject.toml
file to work. If you run it from a directory without this file, you'll get an error.
Virtual environment behavior: If you run uv sync
in a directory that contains pyproject.toml
but doesn't have a .venv
folder, UV will create a new virtual environment in that directory. This is why it's important to use --project
to specify the correct project path, or make sure you're in the right directory to avoid creating unwanted .venv
folders.
Extensions are added by modifying the pyproject.toml
file in your project root.
pyproject.toml
and locate the dependencies section:dependencies = [
"flet==0.28.3"
]
For extensions hosted on GitHub, use this format:
dependencies = [
"flet==0.28.3",
"flet-animated-border @ git+https://github.com/Wanna-Pizza/flet-animated-border.git@main"
]
Format explanation:
flet-animated-border
- The package name@ git+
- Indicates installation from Githttps://github.com/Wanna-Pizza/flet-animated-border.git
- Repository URL@main
- Specifies the branch (use @main
, @master
, or specific tag)For extensions published on PyPI:
dependencies = [
"flet==0.28.3",
"flet-custom-widget==1.2.3"
]
uv sync
For macOS:
uv run flet build macos -v
For Windows:
uv run flet build windows -v
For Linux:
uv run flet build linux -v
What this does:
-v
flag provides verbose output for debuggingFor macOS/Linux:
uv run flet run src/main.py
For Windows:
uv run flet run src\main.py
Alternative (hot reload for development):
For macOS/Linux:
uv run flet -r src/main.py
For Windows:
uv run flet -r src\main.py
What this does:
-r
flag enables hot reload (automatically restarts when files change)dependencies = [
"flet==0.28.3",
"flet-animated-border @ git+https://github.com/Wanna-Pizza/flet-animated-border.git@main",
"flet-charts @ git+https://github.com/example/flet-charts.git@v1.0",
"flet-widgets==2.1.0"
]
import flet as ft
from flet_animated_border import AnimatedBorder # Import your extension
For macOS/Linux:
# 1. Create project
uv run flet create my_awesome_app
cd my_awesome_app
# 2. Edit pyproject.toml to add extensions
# (add your extensions to the dependencies list)
# 3. Install dependencies
uv sync
# 4. Build for your platform
uv run flet build macos -v
# 5. Run with hot reload
uv run flet -r src/main.py
For Windows:
# 1. Create project
uv run flet create my_awesome_app
cd my_awesome_app
# 2. Edit pyproject.toml to add extensions
# (add your extensions to the dependencies list)
# 3. Install dependencies
uv sync
# 4. Build for your platform
uv run flet build windows -v
# 5. Run with hot reload
uv run flet -r src\main.py
Solution: UV is not installed. Run pip install uv
first.
Solution: Make sure you're in the correct directory and using the right command for your OS.
Solutions:
uv sync
after adding to pyproject.toml
uv run flet build [platform] -v
Solutions:
uv list
to see installed packagesSolutions:
uv run flet build [platform] -v
# Check installed packages
uv list
# Update all dependencies
uv sync --upgrade
# Remove a dependency
# (Edit pyproject.toml to remove the line, then run)
uv sync
# Check UV version
uv --version
pyproject.toml
for reproducible buildsCongratulations! You now have a complete understanding of how to add and use user extensions in Flet. Start building amazing applications with the power of community-created widgets!