Skip to main content

A simple HTTP server that serves files, even on file change

Project description

Sure! Here's an updated README.md file based on the new code base:

PyAutoReloadHTTPServer

PyAutoReloadHTTPServer is a simple Python package that provides an HTTP server with automatic reloading functionality. It allows you to serve static files and dynamically reload them whenever they are modified, created, or destroyed. You no longer have to restart your local server to load changed files, this will serve files as they're added and changed. Give it a shot!

Installation

You can install PyAutoReloadServer using pip:

pip install pyautoreloadserver

Usage

The easiest way to run it, is to use it from the command line

pyautoreloadserver -n localhost -p 5555 -r .

The flags above can be summarized as follows

  • n: the hostname
  • p: the port
  • r: the root directory to monitor

To use PyAutoReloadHTTPServer, create an instance of the AutoReloadHTTPServer class and call the serve method to start the server. By default, the server listens on localhost and port 8000, and serves files from the current directory.

from pyautoreloadserver import AutoReloadHTTPServer

# Create an instance of AutoReloadHTTPServer
server = AutoReloadHTTPServer()

# Start the server
server.serve()

You can customize the server behavior by providing optional arguments to the AutoReloadHTTPServer initializer:

  • host (str): The hostname or IP address to bind the server to (default: "localhost").
  • port (int): The port number to listen on (default: 8000).
  • root (str): The root directory to serve files from (default: ".").
  • delay (float): The delay between serving requests (default: 0.001 seconds).
  • ServerClass (TCPServer): The server class to use (default: HTTPServer).
  • RequestHandlerClass (BaseHTTPRequestHandler): The request handler class to use (default: SimpleHTTPRequestHandler).
from pyautoreloadserver import AutoReloadHTTPServer

# Create an instance of AutoReloadHTTPServer with custom options
server = AutoReloadHTTPServer(host="0.0.0.0", port=8080, root="/path/to/files")

# Start the server
server.serve()

Once the server is running, you can visit the specified host and port in your web browser to access the served files.

To stop the server, call the stop method:

server.stop()

Although you'll probably want to start this in a separate thread/process because the server is running a loop that may block.

Logging

PyAutoReloadHTTPServer logs informational messages using the logging module. By default, the log level is set to logging.INFO, but you can configure it according to your needs.

import logging

# Set the log level to DEBUG for more detailed logs
logging.basicConfig(level=logging.DEBUG)

Contributing

Contributions to PyAutoReloadHTTPServer are welcome! If you find a bug, have a feature request, or want to contribute code, please open an issue or submit a pull request on the GitHub repository.

License

This project is licensed under the MIT License.

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

pyautoreloadserver-0.0.2.tar.gz (5.7 kB view hashes)

Uploaded Source

Built Distribution

pyautoreloadserver-0.0.2-py3-none-any.whl (7.4 kB view hashes)

Uploaded Python 3

Supported by

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