HTTP built from raw sockets.

A complete HTTP/1.1 server framework in Python. No Flask. No dependencies. Just socket.socket() and hand-written protocol parsing.

222 passing tests
4,500+ lines of Python
0 dependencies

Every HTTP framework hides the protocol behind abstractions. ServeKit doesn't. It opens raw TCP sockets, reads bytes off the wire, parses request lines and headers by hand, matches routes, runs middleware, serializes responses, and pushes bytes back. If you want to understand what happens between a browser and a server — read this code.

Quickstart
from servekit import ServeKit

app = ServeKit()

@app.get("/")
def home(req, res):
    res.json({"message": "Hello from raw TCP sockets!"})

@app.get("/users/{id}")
def get_user(req, res):
    user_id = req.params["id"]
    res.json({"id": user_id})

app.listen(8080)
What's inside

HTTP/1.1 Parser

Request line, headers, Content-Length bodies, chunked transfer encoding. All parsed from raw bytes.

URL Router

Exact paths, parameterized segments {id}, wildcards *path, route groups, priority resolution.

Middleware Chain

CORS, gzip compression, rate limiting, basic auth, request logging. Stack them, short-circuit them.

WebSocket (RFC 6455)

HTTP upgrade handshake, frame encode/decode, masking, text/binary/ping/pong/close opcodes.

Static File Server

MIME types, ETag caching, 304 Not Modified, directory traversal prevention, index files.

Non-blocking I/O

selectors.DefaultSelector event loop with thread pool. Concurrent requests without async/await.

Architecture
  TCP socket ─→ selectors event loop ─→ thread pool
       │
       ▼
  Raw bytes ─→ HTTP Parser ─→ Request object
       │
       ▼
  Router (exact │ param │ wildcard)
       │
       ▼
  Middleware chain (before → handler → after)
       │
       ▼
  Response builder ─→ serialize to bytes ─→ TCP send

Read the code. Run the tests. Build on it.

View on GitHub