Skip to content

alex-dicko/Web-Framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Web-Framework

A tiny WSGI web framework written from scratch, for learning. The goal was to mash together the parts I like from Django and FastAPI: Django's declarative models/ORM and template rendering, and FastAPI's lightweight decorator-based routing.

Features

  • Decorator routing (@app.route("/")), FastAPI-style, with path params via parse (e.g. "/users/{id}").
  • Function and class-based views — a class handler dispatches on HTTP method (get, post, ...), Django-style.
  • A baby ORM — declare models with CharField / IntegerField, call .save(), and tables auto-migrate on startup.
  • SQLite-backed, no config needed (db.sqlite3 by default).
  • Jinja2 templates via app.render_template(...).
  • Response types: HttpResponse, JsonResponse, HTMLResponse.
  • Pluggable middleware stack (toggle with Config(activate_middleware=...)).
  • WSGI compatible — runs under gunicorn or any WSGI server.

How it borrows from each

From FastAPI From Django
@app.route decorator routing Model + Field declarative ORM
Single app callable object class Meta: app = app model config
Lightweight, minimal boilerplate Auto-migrations on model registration
JsonResponse for APIs Jinja2 template rendering + base templates

Example

from api import API
from config import Config
from http.types import HttpRequest, HttpResponse
from orm.models import Model, IntegerField, CharField
from utils import bind_json_to_class

app = API(config=Config(activate_middleware=False, template_dirs=["templates"]))

@app.model()
class User(Model):
    age = IntegerField(default=100)
    name = CharField()

    class Meta:
        app = app

@app.route("/")
def home(request: HttpRequest):
    user = bind_json_to_class(User, request.body)
    user.save()
    return HttpResponse("Hello World")

Running

gunicorn app:app

A learning project.

About

Web Framework built in python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors