Skip to main content

Simple Web Framework by Simplendi

Project description

SimpleFramework

A lightweight WSGI web framework for Python that provides essential tools for building web applications with minimal complexity.

Features

  • WSGI-compliant: Compatible with any WSGI server
  • Flexible routing: Support for URL patterns with regex, static file serving, and request forwarding
  • Session management: Built-in session handling with database persistence
  • Cookie handling: Full cookie support including HttpOnly, Secure, and SameSite attributes
  • Request parsing: Support for form data, JSON, and multipart/form-data
  • HTTP exceptions: Clean exception handling for HTTP status codes
  • Email support: Built-in email sending capabilities
  • Static file serving: Efficient static file handler with MIME type detection

Installation

pip install SimpleFramework

Quick Start

from framework import Application, Router, State

# Create application and router
app = Application()
router = Router()

# Define a route
def hello(state):
    state.response.body = "Hello, World!"
    return state

router.addMapping(r'^/$', hello)

# Set the router as the controller
app.controller = router

# Run the development server
if __name__ == '__main__':
    app.serve(port=8000)

Core Components

Application

The main application class that handles WSGI requests and manages the request/response lifecycle.

Router

Handles URL routing with support for:

  • Regular expression patterns
  • Static file serving
  • Request forwarding to sub-applications
  • HTTP method filtering

State

Encapsulates request, response, and session data for each request.

Request

Provides access to:

  • HTTP method, headers, and cookies
  • Query parameters and form data
  • JSON request bodies
  • Accept headers (content negotiation)

Response

Manage responses with:

  • Status codes
  • Headers and cookies
  • Body content (text, JSON, binary)
  • Redirects

Session

Dictionary-like session storage with:

  • Automatic session ID generation (64-byte secure random IDs)
  • Expiration management
  • Database persistence support

Configuration

from framework import Config

config = Config()
config["session_cookie"] = "session_id"
config["session_lifetime"] = 1  # hours
config["session_httponly"] = True
config["session_secure"] = True
config["session_samesite"] = "Lax"  # "Strict", "Lax", or "None"

Examples

Handling JSON Requests

def api_endpoint(state):
    if state.request.content_type.startswith("application/json"):
        data = state.request.body
        state.response.setJsonBody({"status": "success", "data": data})
    return state

Using Sessions

def login(state):
    state.session["user_id"] = 123
    state.session["username"] = "john"
    state.response.body = "Logged in!"
    return state

Static Files

router.addStaticMapping(r'^/static/', '/path/to/static/files')

Setting Cookies

def set_cookie(state):
    state.response.cookies["my_cookie"] = "value"
    state.response.cookies.setHttpOnly("my_cookie", True)
    state.response.cookies.setSecure("my_cookie", True)
    state.response.cookies.setSameSite("my_cookie", "Strict")
    return state

Requirements

  • Python 3.7+

License

MIT License

Author

Simplendi - info@simplendi.com

Repository

https://github.com/Simplendi/SimpleFramework

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

simpleframework-1.4.8-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file simpleframework-1.4.8-py3-none-any.whl.

File metadata

File hashes

Hashes for simpleframework-1.4.8-py3-none-any.whl
Algorithm Hash digest
SHA256 c20e935b302f9c429934859ad232b06ac22a04984a7e0d3953c553b790311757
MD5 142830a50d267c86ac715dc864ed5055
BLAKE2b-256 8f1b5ecec181ffba65fa28b1aaa6d66a2e92d68b66ea4332df5a6254d07313c9

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