uHTTP: A Simple and Fast Python Web Framework

µHTTP - Stupid web development

µHTTP emerged from the need of a simple web framework. It's great for micro-services, small applications, AND monolithic monsters.

In µHTTP there is no hidden logic. Everything is what it seems.


  • Stupid simple, seriously, there are maybe 15 lines of "real" code in it. No external dependencies.
  • Extremely modular, entire extensions can just follow the simple App pattern.
  • Very flexible, you can even raise responses.
  • Quite fast, because size matters.
  • Safe, due to its small attack surface.
  • Great learning device.

The rant.


µHTTP is on PyPI.

pip install uhttp

You might also need an ASGI server. I recommend Uvicorn.

pip install uvicorn

Hello, world!

from uhttp import App

app = App()

def hello(request):
    return f'Hello, {request.ip}!'


#!/usr/bin/env python3

from uhttp import App, Response

app = App()

def open_db(state):
    state['clients'] = []
    state['db'] = [
            'title': 'The Art of Riding Bunnies: A Comprehensive Guide.',
            'author': 'grace'
            'title': 'Vanilla Infusions: Culinary Delights and Sweet Sensations.',
            'author': 'joe'

def log_client(request):
        'ip': request.ip,
        'user-agent': request.headers.get('user-agent')

def incoming(request):
    print(f'Incoming request from {request.ip}')

def all_books(request):
    return {'books': request.state['db']}

def from_author(request):
    return {
        'books': [
            book for book in request.state['db']
            if book['author'] == request.params['author']

def get_user(request):
    user = request.args.get('user')
    if user not in ('grace', 'joe', 'stevens'):
        raise Response(401)
    return user

def new(request):
        'title': request.form.get('title', ''),
        'author': get_user(request)
    return 201

def cors(request, response):
    if request.headers.get('origin'):
        response.headers['access-control-allow-origin'] = '*'

def close_db(state):
    del state['db']

def print_all_clients(state):
    for client in state['clients']:
        print(client['ip'], client['user-agent'])

if __name__ == '__main__':
    import uvicorn


API Reference


µHTTP doesn't come with bells and whistles.

If you want more, search for µHTTP extensions.


Feel free to contribute in any way you'd like. :D

Download Details:

Author: 0x67757300
Source Code: https://github.com/0x67757300/uHTTP 
License: MIT license

#python #web #framework 

uHTTP: A Simple and Fast Python Web Framework
1.40 GEEK