Hump (a defining part of grizzly's neck) is a zero-dependency simple async web server framework for registering request handlers
Project description
Hump
Hump (a defining part of grizzly's neck) is a zero-dependency simple async web server framework for registering request handlers
Why
- 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
How
- 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
Usage example
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)
Limitations
- HTTP/1.1 only, no HTTPS
- No automatic headers handling
- No automatic json response handling, only
strtoResponsewrapping
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hump-1.0.0.tar.gz.
File metadata
- Download URL: hump-1.0.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b37fd2699c376262fccfbb87e4c3424fe630402c19efa6be8f11176fcb4a7a3d
|
|
| MD5 |
cd5dc7efc4a6941b316ccd03a543be4c
|
|
| BLAKE2b-256 |
30dc32927573d6694254c0e5ae2d958e3da0433c9afd834ecf59c2cf4681e283
|
File details
Details for the file hump-1.0.0-py3-none-any.whl.
File metadata
- Download URL: hump-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2d373598896f6d8b12a6dd460c6fa47c7b377544f9e6e84d9d24dece2fb3957
|
|
| MD5 |
a9ac74d0f43c8d0eaa8fd80ed56b124c
|
|
| BLAKE2b-256 |
a2d3fa81cdb96bbe2fe5aa56c60adf049d10c194e35769a42c78b416a5855230
|