ashwin271/faststatic

A lightweight, high-performance static file server built with FastAPI. FastStatic provides an easy way to serve static files with automatic path redirection, logging, and error handling.

โ˜… 0Forks 0PythonGitHub โ†—Compare

README

FastStatic

A lightweight, high-performance static file server built with FastAPI. FastStatic provides an easy way to serve static files with automatic path redirection, logging, and error handling.

Features

  • ๐Ÿš€ High-performance static file serving
  • ๐Ÿ“ Automatic directory creation
  • ๐Ÿ”„ Smart path redirection
  • ๐Ÿ“ Comprehensive logging with rotation
  • โšก Built with FastAPI for maximum performance
  • ๐Ÿ›ก๏ธ Built-in error handling
  • ๐Ÿ” OpenAPI documentation included
  • ๐Ÿ’“ Health check endpoint

Prerequisites

  • Python 3.7+
  • pip (Python package installer)

Installation

  1. Clone the repository:
git clone https://github.com/ashwin271/faststatic.git
cd faststatic
  1. Create a virtual environment and activate it:
python -m venv env
source env/bin/activate  # On Windows: env\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt

Usage

  1. Place your static files in the app/static directory
  2. Run the server:
cd app
python main.py

The server will start on http://0.0.0.0:8800 by default.

Accessing Files

  • Access files directly via /static/filename (e.g., /static/dog.jpg)
  • Any request to /filename will automatically redirect to /static/filename
  • Root path (/) shows a welcome message
  • Health check available at /health

API Documentation

Once the server is running, you can access:

  • Swagger UI documentation at /docs
  • ReDoc documentation at /redoc

Logging

Logs are stored in logs/app.log with the following configuration:

  • Rotation: 500 MB
  • Retention: 10 days
  • Level: INFO
  • Format: YYYY-MM-DD HH:mm:ss | LEVEL | message
  • Includes backtrace and diagnosis for errors

Project Structure

.
โ”œโ”€โ”€ app
โ”‚   โ”œโ”€โ”€ main.py        # Main application file
โ”‚   โ””โ”€โ”€ static         # Static files directory (you can add your files here)
โ”œโ”€โ”€ logs               # Log files directory (created automatically)
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ requirements.txt

Configuration

The following settings can be modified in main.py:

STATIC_DIR = Path("static")  # Static files directory
HOST = "0.0.0.0"            # Host address
PORT = 8800                 # Port number

Error Handling

  • Automatic 404 responses for missing files
  • JSON-formatted error responses
  • Comprehensive error logging

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributors

ashwin271

Issues