Hump (a defining part of grizzly's neck) is a zero-dependency simple async web server framework for registering request handlers
- Because dataclasses have smaller overhead than Pydantic models.
- "I understand how something works only if i know how to create it myself"
- Making software from scratch is something that is inherently fun and challenging
- Python
socketpackage provides the means to connect/accept withAF_INET(TCP/IP) protocol - Create a socket, set it up as non-blocking, bind to
host, portpair - Listen for incoming connections on socket
- When client connects, accept, create an asyncio task to handle this request further, main return to 3 to accept other clients
- Parse incoming request into dataclass
Requestmodel, pass it into registered async handler byurl, methodpair - Gather response data/
Responseobject, encode to bytes and send it back - Close socket and finish task
import asyncio
from hump import Hump, Request
app = Hump("", 8342)
@app.get("/")
async def index(request: Request):
return "Hello, world!"
asyncio.run(app.serve())And that's it, you can run this example, go to your browser and perform http request to localhost:8342 to get Hello, world! answer.
You can also return another HTTP status code with data attached like this
from hump import Response, statuses
# ... As defined in example usage before
@app.get("/")
async def index(request: Request)
return Response("Howdy!", statuses.IM_A_TEAPOT)- HTTP/1.1 only, no HTTPS
- No automatic headers handling
- No automatic json response handling, only
strtoResponsewrapping