Skip to main content

Hump (a defining part of grizzly's neck) is a zero-dependency simple async web server framework for registering request handlers

Project description

Hump

PyPI - License PyPI - Types PyPI - Version PyPI - Python Version

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

  1. Python socket package provides the means to connect/accept with AF_INET (TCP/IP) protocol
  2. Create a socket, set it up as non-blocking, bind to host, port pair
  3. Listen for incoming connections on socket
  4. When client connects, accept, create an asyncio task to handle this request further, main return to 3 to accept other clients
  5. Parse incoming request into dataclass Request model, pass it into registered async handler by url, method pair
  6. Gather response data/Response object, encode to bytes and send it back
  7. 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

  1. HTTP/1.1 only, no HTTPS
  2. No automatic headers handling
  3. No automatic json response handling, only str to Response wrapping

Download files

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

Source Distribution

hump-1.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hump-1.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file hump-1.1.0.tar.gz.

File metadata

  • Download URL: hump-1.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for hump-1.1.0.tar.gz
Algorithm Hash digest
SHA256 981666e85487445c8f1ccfacdb2f6cd1d766989b41902c8699d33f36ea338fcc
MD5 6eacf5d195a2cb520111fa64261bcaf0
BLAKE2b-256 6d782adf77028b81e09850683d04296ad3a6a9e911bdcc392fbc57f7ddcb95df

See more details on using hashes here.

File details

Details for the file hump-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: hump-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for hump-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b49d74215443951909fb01a9ab3f771faa83f15c34ca19683787ee4a8e8e055
MD5 8f3b3cf910972f3c56d812933a7da925
BLAKE2b-256 95c76a7b2b242f9e1aee9bbdd08a6f7dd03d0542f0a2a1ce9f90baa2e56bdc73

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page