Skip to content
This repository was archived by the owner on Jul 8, 2026. It is now read-only.

KanekiEzz/pyBackend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SmallFast (pyBackend) 🚀

A lightweight, fast, and easy-to-use Python web framework built for speed and simplicity. Inspired by modern frameworks like FastAPI, SmallFast provides an elegant API to build web applications and APIs quickly with minimal boilerplate.

Features ✨

  • Intuitive Routing: Decorator-based routing for GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD, and flexible custom routes.
  • Path Parameters: Easily extract values from URL paths (e.g., /users/{id}).
  • Data Validation & Parsing: Automatic parsing of request bodies into Python dataclasses.
  • Middleware Support: Robust support for both global and route-level middleware. Use req.state to pass data between middleware and handlers.
  • Built-in Admin Panel: Out-of-the-box admin application with authentication and session management.
  • Error Handling: Raised HTTPException class to handle errors gracefully and provide consistent responses.

Screenshots 📸

Explore the admin panel interface with our interactive screenshots:

Quick Navigation

Installation 📦

Clone the repository and start building:

git clone https://github.com/yourusername/SmallFast.git
cd SmallFast
# We recommend using a virtual environment
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt # (if any)

Quick Start 🏁

Create an app.py file with your routes:

from pybackend import App, HTTPException
from dataclasses import dataclass

app = App()

# Basic GET Request
@app.get("/")
def home():
    return {"status": "online", "message": "Welcome to SmallFast!"}

# Path Parameters
@app.get("/users/{user_id}")
def get_user(user_id):
    if user_id != "1":
        raise HTTPException(404, "User not found")
    return {"id": user_id, "name": "Admin"}

# Automatic Request Body Parsing using Dataclasses
@dataclass
class UserCreate:
    name: str
    email: str

@app.post("/users")
def create_user(user: UserCreate):
    # 'user' is automatically parsed from JSON body to the UserCreate dataclass
    return {"created": True, "name": user.name, "email": user.email}

if __name__ == "__main__":
    app.run(port=8080)

Run your code:

python app.py

Your server will start and be available at http://localhost:8080.

Middleware 🔌

SmallFast supports powerful middleware injection to handle requests and responses globally or per route.

Global Middleware

@app.middleware
def request_logger(req, res, next):
    print(f"[{req.method}] {req.path}")
    # Proceed to next middleware or route handler
    return next()

Route-Level Middleware

Route-level middlewares can be used to protect specific endpoints (e.g., Auth Guards).

def require_api_key(req, res):
    if req.headers.get("X-API-Key") != "secret":
        raise HTTPException(401, "Missing or invalid API key")

@app.get("/secure", middleware=[require_api_key])
def secure_data(req):
    return {"authorized": True, "data": "Top secret information"}

Middleware can:

  • Read and mutate the req (Request) object.
  • Pass shared data using req.state.
  • Stop the request prematurely by raising an HTTPException.
  • Block or proceed execution by utilizing the next function.

Built-In Admin Panel 🛡️

SmallFast ships with a built-in interactive Admin Panel. By enabling it, you get login pages, secure cookie authentication, and routing settings out of the box!

app = App()

admin_panel = app.admin_panel
admin_panel.register()

if __name__ == "__main__":
    app.run(port=8080, admin=True)

Navigate to http://localhost:8080/admin/login to access the portal. The built-in panel supports role-based access, credential updates, and session cookies for a secure administrative experience.

About

A lightweight Python web framework built from scratch to understand how modern frameworks like FastAPI work under the hood. It includes routing, middleware, request/response handling, exceptions, and automatic API documentation support.

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors