Skip to main content

A simple, dynamic, decorator-based HTTP server inspired by Node.js's Express. Supports trio, TLS and WebSockets.

Project description


dhttp, which is pretty short for decorable HTTP, is a simple, yet dynamic, HTTP server written for Python 3.
It is inspired by Node.js's Express library.

"Decorable" is a reference to how extensively decorators are used throughout this project. They are very useful, and are one of the nicest syntaxes for a callback system like this.

Example code

import dhttp
import random

app = dhttp.DHTTPServer(int(sys.argv[1]) if len(sys.argv) > 1 else 8005)

app.alias('/index', '/')
app.alias('/index.htm', '/')
app.alias('/index.html', '/')

test_index = """<!DOCTYPE html>
        <meta charset="utf-8" />
        <title>My first DHTTP server</title>

        <p><b>dhttp {version}</b> is now running on your machine.</p>
        <p>How about <i>{party}</i> to comemorate? :)</p>

party_stuff = [
    'a bottle of wine', 'a bottle of champagne', 'a big party',
    'THE party, just', 'THE party', 'lots of cats', 'partyception',
    'balloons and cakes', 'a big-endian cake', 'lots of confetti',
    'the Confetti-o-Tron 2000', 'HTTP juice', 'Spicy Bytes',
    'antimatter', 'cats writing code', 'a smile breaking the 4th wall'

def serve_index(req, res):
        party = random.choice(party_stuff),
        version = DHTTP_VERSION

def print_log(log):
    if log.request.get_header('X-Forwarded-For') is not None:
        log.ip = log.request.get_header('X-Forwarded-For')
        print(log, '  (forwarded)')


def on_serve():
    print(f"   == Listening on port: {app.port} ==")

Project details

Download files

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

Files for dhttp, version 1.3.3
Filename, size File type Python version Upload date Hashes
Filename, size dhttp-1.3.3-py3-none-any.whl (30.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size dhttp-1.3.3.tar.gz (27.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page