This example demonstrates how to package a FastHTML application as a portable Linux AppImage using micromamba for Python environment management.
- Portable: Single executable file that runs on most Linux distributions
- Self-contained: Includes Python runtime and all dependencies via micromamba
- Browser modes: Can open in default browser, standalone window, or headless
- Environment management: Uses micromamba for reproducible Python environments
- No installation required: Just download and run
fasthtml-appimage-example/
├── build-resources/ # Build resource (used during build)
│ ├── AppRun # Entry point script
│ └── fasthtml-demo.desktop # Desktop entry file
├── build.sh # Build script
├── environment.yml # Conda environment specification
├── README.md # This file
├── requirements.txt # Python package requirements
└── src/ # FastHTML application source
└── app.py # Main FastHTML application
To build the AppImage, you need:
- Linux system (x86_64 or aarch64)
wgetandfilecommands- Internet connection (for downloading tools and packages)
Optional:
ImageMagick(for icon generation)
- Clone or download this example:
git clone https://github.com/cj-mills/fasthtml-appimage-example.git
cd ./fasthtml-appimage-example- Run the build script:
./build.shThe build script will:
- Download micromamba and AppImage tools
- Create a conda environment with FastHTML and dependencies
- Package everything into an AppImage
- Output:
FastHTMLDemo-1.0.0-x86_64.AppImage
./FastHTMLDemo-1.0.0-x86_64.AppImageThis opens your FastHTML app in the default browser.
FASTHTML_BROWSER=app ./FastHTMLDemo-1.0.0-x86_64.AppImageOpens in a chromeless browser window (if Chrome/Chromium is installed).
FASTHTML_BROWSER=none ./FastHTMLDemo-1.0.0-x86_64.AppImageRuns the server without opening a browser.
DEBUG=1 ./FastHTMLDemo-1.0.0-x86_64.AppImageShows detailed debug information.
# Enter a shell with the FastHTML environment
./FastHTMLDemo-1.0.0-x86_64.AppImage shell
# Run Python directly
./FastHTMLDemo-1.0.0-x86_64.AppImage python -c "import fasthtml; print(fasthtml.__version__)"
# Install additional packages
./FastHTMLDemo-1.0.0-x86_64.AppImage pip install some-package
# Extract the AppImage contents (for inspection)
./FastHTMLDemo-1.0.0-x86_64.AppImage --appimage-extractFASTHTML_HOST: Server host (default: 127.0.0.1)FASTHTML_PORT: Server port (default: auto-assign)FASTHTML_BROWSER: Browser mode -default,app, ornoneDEBUG: Enable debug output
-
AppRun Script: The entry point that:
- Sets up the micromamba environment
- Configures Python paths
- Launches the FastHTML application
-
Micromamba: Provides isolated Python environment:
- Bundled inside the AppImage
- Contains Python 3.11 and all dependencies
- Completely isolated from system Python
-
FastHTML Application: Runs as a local web server:
- Auto-finds available port
- Opens browser automatically
- Serves the web application locally
- Edit
environment.ymlfor conda packages:
dependencies:
- python=3.11
- numpy # Add conda packages here
- pip:
- -r requirements.txt- Edit
requirements.txtfor pip-only packages:
python-fasthtml>=0.12.27
sqlite-minutils>=4.0.3
new-package==1.0.0
- Rebuild the AppImage
- Edit
src/app.pywith your FastHTML application - Add additional Python files to
src/as needed - Rebuild the AppImage
- Edit
AppDir/fasthtml-demo.desktopfor app name/description - Replace the icon by providing a PNG file
- Update
APP_NAMEandAPP_VERSIONinbuild.sh
The AppImage size can be reduced by:
- Using pip-only dependencies (skip conda packages when possible)
- Cleaning build artifacts (already done in build script)
- Using
--no-depsfor packages with unnecessary dependencies - Excluding test files and documentation from packages
- Make it executable:
chmod +x FastHTMLDemo-*.AppImage - Check architecture:
file FastHTMLDemo-*.AppImage - Try extracting:
./FastHTMLDemo-*.AppImage --appimage-extract
- Ensure all dependencies are in
environment.ymlorrequirements.txt - Check debug output:
DEBUG=1 ./FastHTMLDemo-*.AppImage - Try rebuilding the AppImage
You can modify this example to bundle multiple FastHTML apps:
- Add multiple apps to
src/ - Modify
AppRunto accept app selection parameter - Create launcher script or menu for app selection
Create a .desktop file in ~/.local/share/applications/:
[Desktop Entry]
Type=Application
Name=My FastHTML App
Exec=/path/to/FastHTMLDemo-1.0.0-x86_64.AppImage
Icon=/path/to/icon.png
Categories=Development;The build script can be integrated into CI/CD pipelines:
# GitHub Actions example
- name: Build AppImage
run: |
cd fasthtml-appimage-example
./build.sh
- name: Upload AppImage
uses: actions/upload-artifact@v2
with:
name: appimage
path: "*.AppImage"