A complete HTTP/1.1 server framework in Python. No Flask. No dependencies. Just socket.socket() and hand-written protocol parsing.
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.
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)
Request line, headers, Content-Length bodies, chunked transfer encoding. All parsed from raw bytes.
Exact paths, parameterized segments {id}, wildcards *path, route groups, priority resolution.
CORS, gzip compression, rate limiting, basic auth, request logging. Stack them, short-circuit them.
HTTP upgrade handshake, frame encode/decode, masking, text/binary/ping/pong/close opcodes.
MIME types, ETag caching, 304 Not Modified, directory traversal prevention, index files.
selectors.DefaultSelector event loop with thread pool. Concurrent requests without async/await.
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