Skip to main content

A lightweight static file server for Flet apps, designed to simplify mobile debugging by serving assets over a local network.

Project description

# **StaticServer Documentation** 🚀

The `StaticServer` class is designed to simplify debugging for mobile devices (iOS/Android) in Flet apps. It serves static files (like images, icons, or text files) from your computer, making them accessible to mobile devices during development. 📱💻

---

## **Why Use StaticServer?** 🤔
When developing for mobile:
- Direct file paths from your computer won’t work on devices. 🚫
- StaticServer hosts your files locally, providing a URL (`server.assets`) that devices can access. 🌐
- Perfect for debugging and testing assets on real devices. 🛠️

---

## **How to Use It** 🛠️

### **1. Installation**
pip install flet-staticserver
from flet_staticserver import StaticServer

2. Basic Setup

Start the server and use it in your Flet app:

import flet as ft
from serve_files import StaticServer

# Initialize the server 🎬
server = StaticServer()

def main(page: ft.Page):
    # Access files using server.assets 🖼️
    page.add(
        ft.Image(src=f"{server.assets}/icon.png"),
        ft.Text(f"Access files at: {server.assets}")
    )

# Run your Flet app 🚀
ft.app(main)

3. Customization Options ⚙️

Customize the server to fit your needs:

  • Change the folder: Serve files from a specific directory.
  • Change the port: Use a different port if needed.
server = StaticServer(
    directory="path/to/your/assets",  # 🗂️ Custom folder
    port=2222                        # 🚪 Custom port
)

4. Accessing Files 📂

Once the server is running, access your files like this:

  • File in root: {server.assets}/file.txt
  • File in subfolder: {server.assets}/images/photo.jpg

Example:

ft.Image(src=f"{server.assets}/images/icon.png")

How It Works 🧙‍♂️

  • The server runs in the background using FastAPI and UVicorn. ⚡
  • It automatically detects your machine's IPv4 address, so devices on the same network can access the files. 🌐
  • Files are served dynamically, making debugging seamless. 🛠️

Example Use Case 🖼️

Display an image from your assets folder on a mobile device:

import flet as ft
from serve_files import StaticServer

# Start the server 🎬
server = StaticServer()

def main(page: ft.Page):
    # Display an image from the server 🖼️
    page.add(
        ft.Image(src=f"{server.assets}/icon.png"),
        ft.Text("Your image is live!")
    )

# Run the app 🚀
ft.app(main)

Why It’s Useful ❤️

  • Solves the problem of inaccessible local files on mobile devices. 📱
  • Simplifies debugging and testing during development. 🛠️
  • Works seamlessly with Flet apps. 🎯

Final Notes 📝

  • The server stops automatically when your app closes.
  • Use server.assets to get the base URL for your files.
  • Happy debugging! 😄👨‍💻👩‍💻

Enjoy building and debugging your Flet apps! 🎉

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flet_assets-0.2.1.tar.gz (7.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flet_assets-0.2.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file flet_assets-0.2.1.tar.gz.

File metadata

  • Download URL: flet_assets-0.2.1.tar.gz
  • Upload date:
  • Size: 7.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for flet_assets-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7ffd8cd9a5fffe21e5d46b91f1b0b9a46f8348a026a953760af0be48d5109962
MD5 1db11b6be45fb5885715508ecc695c88
BLAKE2b-256 aeeb2f386f623b397c84d9e2abb14c9b8e07bad69cb00571261922224da05119

See more details on using hashes here.

File details

Details for the file flet_assets-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: flet_assets-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for flet_assets-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 150e6255d005305b57c59c1cf49ca757defda8ae35afd4707cf48ed556cd39f7
MD5 cfdc26f114531a35e4b26a718274ac8d
BLAKE2b-256 f31f2f1d6678c61d01a32e4f3c808bab283bc3eb7f33ca4eb723d52e24ba88b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page