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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file pyautoreloadserver-0.0.2.tar.gz.

File metadata

  • Download URL: pyautoreloadserver-0.0.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for pyautoreloadserver-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2280902148e7c3c79580a65e2d10dd1c9b398c3f7c3a4aea36fe5b5db7c1490e
MD5 bdd2fe82669faef62ee0c22345181aa8
BLAKE2b-256 75bd4bc24f842980a8f9a740711449061e02ca6a5172caf6d096d1862773d401

See more details on using hashes here.

File details

Details for the file pyautoreloadserver-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pyautoreloadserver-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5a72652c22a5617c03da83c1cc40e879c12e37c1d0c1d9d69f2445e51ee7b894
MD5 2db6e7f6871c415060bd77e7b73a1ada
BLAKE2b-256 34e05b6b77460a71c15cfd5ad4c77d4ee6054a0e6afb336cd626cfa0524cd3de

See more details on using hashes here.

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