PitchHut logo
Ultra-fast HTTP server for Python development.
Pitch

httpit is a high-performance, lightweight HTTP server built as a Python C extension. Designed for rapid development, it offers exceptional speed, easy command-line usage, and supports modern web standards. With minimal memory footprint and powerful features like directory listing and access control, httpit simplifies file serving for developers.

Description

httpit logo

httpit is an ultra-fast and lightweight HTTP server specifically designed for static file serving in Python. By leveraging C extensions, httpit delivers exceptional performance and efficiency, making it an ideal choice for both development and production workloads.

Key Features

  • Blazing Fast: Built with a zero-copy sendfile() support, httpit ensures rapid file serving.
  • Minimal Footprint: It is lightweight, with a minimal memory footprint and reduced dependencies.
  • User-Friendly: The simple command-line interface and Python API make it easy to set up and manage.
  • Directory Listing: Provides a built-in HTML interface for browsing directories.
  • Enhanced Security: Supports basic authentication and access control to safeguard resources.
  • Modern Protocols: Fully compliant with HTTP/1.1, IPv6, Keep-Alive, and range requests.
  • Production Ready: Includes features like access logging, daemon mode, and custom MIME types for professional use.

Quick Start

Start quickly by serving files directly from the current directory on port 8000:

httpit

Or specify a directory:

httpit /path/to/files

For a custom port:

httpit 8080

Combine options to serve from a specific directory on a custom port:

httpit /path/to/files 8080

Command Line Usage

Basic Commands

  • To serve the current directory on port 8000 (default):
httpit
  • Serve on a specific port:
httpit 8080
  • Serve a specific directory:
httpit /var/www/html
  • Serve a specific directory on a specific port:
httpit /var/www/html 8080

Advanced Options

Utilize advanced features to optimize server performance:

httpit -d                 # Enable debug output
httpit -F                 # Disable directory listing
httpit -l access.log      # Enable access logging
httpit -i 192.168.1.100   # Bind to specific IP
httpit -C                 # Enable CORS headers
httpit -I index.php       # Custom index file
httpit -t 30              # Set connection timeout (seconds)
httpit -c 100             # Set maximum connections
httpit -D                 # Run in background (daemon mode)
httpit -a username:password # Enable basic authentication
httpit -n www.example.com  # Serve specific virtual host
httpit -m /etc/mime.types  # Custom mime types file

Complete Example

A complete command to run httpit in a production environment with logging, authentication, and custom settings:

httpit /var/www/html 443 \ 
  -D \ 
  -l /var/log/httpit/access.log \ 
  -a admin:secure_password \ 
  -F \ 
  -t 60 \ 
  -c 1000

Python API

Integrate httpit directly within Python applications:

Basic Usage

from httpit import HTTPServer

# Create and start the server
server = HTTPServer(port=8080, root="/var/www/html")
server.start()

# Check if the server is running
if server.is_running():
    print("Server is running")

# Stop the server
server.stop()

Context Manager

Using httpit as a context manager for better resource management:

from httpit import HTTPServer

with HTTPServer(port=8080) as server:
    print(f"Serving at http://localhost:{server.port}")
    input("Press Enter to stop...")

Advanced Configuration

Establish comprehensive settings to fit specific needs:

server = HTTPServer(
    port=8080,
    root="/var/www/html",
    host="www.example.com",
    bind_ip="0.0.0.0",
    debug=True,
    no_listing=True,
    auth="user:pass",
    log="access.log",
    cors="*",
    timeout=60,
    max_connections=1000,
    index="index.php"
)
server.start()

Performance

httpit is engineered for high performance with the following features:

  • Zero-copy file serving via the sendfile() system call.
  • Minimal memory allocations during request processing.
  • An efficient event loop, balancing load with epoll/kqueue support.
  • Smart caching mechanisms for directory listings and file metadata.

Benchmarking shows that httpit can serve static files 2-5 times faster than conventional Python web servers.

Use Cases

httpit is versatile in its applications:

  • Static file serving for websites, documentation, and downloadable resources.
  • A reliable development server for quick testing.
  • Media streaming capabilities for audio and video with range request support.
  • A simple file-sharing server on local networks.
  • Acting as a backend for content delivery networks (CDNs).
  • A minimal footprint server for use in Docker containers.

Comparison with Alternatives

Featurehttpithttp.servernginxApache
Performance⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
Ease of Use⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
Memory Usage⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
Features⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
Python Integration⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐

Security Considerations

httpit is exclusively designed for serving static files. To ensure secure usage:

  • Use the -F flag to disable directory listing in production environments.
  • Implement authentication (-a) for sensitive content.
  • Operate as a non-root user wherever possible.
  • Consider employing a reverse proxy for HTTPS configurations in production.

Troubleshooting

Common issues and their resolutions:

Port Already in Use

If receiving the "Port already in use" error:

lsof -i :8000

To forcefully terminate any running httpit instances:

pkill -f httpit

Permission Denied

Should permission issues arise while serving from restricted directories:

# Preferred solution:
cp -r /etc/myapp ~/myapp
httpit ~/myapp

Silent Exit

If there's no output when starting:

httpit -d   # Run with debug to see encountered errors

Contributing

For feature requests and to report issues, contributions are encouraged through the httpit repository or the project's website at httpit.rodmena.co.uk.

About RODMENA LIMITED

RODMENA LIMITED specializes in high-performance software solutions and web technologies. For more details about our services and products, visit rodmena.co.uk.

0 comments

No comments yet.

Sign in to be the first to comment.