Skip to main content

Python Web Framework built for learning purposes

Project description

PyFlexo

A modern, lightweight and extensible WSGI web framework for Python.

Python License Tests Version


Why PyFlexo?

PyFlexo is a lightweight WSGI web framework focused on simplicity, readability, and extensibility.

Instead of hiding how web applications work, PyFlexo provides a clean API while remaining close to the WSGI specification. It is suitable for learning, small services, REST APIs, and custom web applications.

Features

  • Simple and intuitive routing
  • Function-based views
  • Class-based views
  • Dynamic URL parameters
  • Built-in template rendering (Jinja2)
  • Static file serving
  • JSON response helper
  • Global exception handlers
  • Middleware support
  • Pure Python implementation
  • WSGI compatible
  • Easy to extend

Installation

Using pip

pip install py_flexo

Using uv

uv add py_flexo

Quick Start

main.py

from py_flexo.app import PyFlexoApp

app = PyFlexoApp()


@app.route("/")
def home(request, response):
    response.text = "Hello, PyFlexo!"

Run your application with any WSGI server.

Example:

gunicorn main:app

Routing

Function Based View

@app.route("/")
def index(request, response):
    response.text = "Hello World"

Route Parameters

@app.route("/hello/{name}")
def hello(request, response, name):
    response.text = f"Hello {name}"

Example

GET /hello/Alice

Response

Hello Alice

Class Based Views

@app.route("/books")
class Book:

    def get(self, request, response):
        response.text = "Book List"

    def post(self, request, response):
        response.text = "Create Book"

Supported methods

  • GET
  • POST
  • PUT
  • PATCH
  • DELETE

Templates

Directory

project/

    templates/
        home.html

Route

@app.route("/home")
def home(request, response):
    response.html = app.template(
        "home.html",
        context={
            "title": "PyFlexo",
            "header": "Welcome"
        }
    )

Template

<!DOCTYPE html>
<html>
<head>
    <title>{{ title }}</title>
</head>

<body>

<h1>{{ header }}</h1>

</body>
</html>

JSON Responses

@app.route("/api")
def api(request, response):

    response.json = {
        "framework": "PyFlexo",
        "version": "0.1.0"
    }

Output

{
    "framework": "PyFlexo",
    "version": "0.1.0"
}

Middleware

from py_flexo.middleware import Middleware


class LoggingMiddleware(Middleware):

    def process_request(self, request):
        print(request.method, request.path)

    def process_response(self, response):
        print(response.status_code)


app.add_middleware(LoggingMiddleware)

Exception Handling

def exception_handler(request, response, exception):

    response.status_code = 500
    response.text = "Internal Server Error"


app.add_exception_handler(exception_handler)

Static Files

Directory

project/

    static/

        style.css
        app.js
        logo.png

Static files are automatically available under

/static/

Example

/static/style.css

Project Structure

project/

│

├── main.py

├── templates/

│   └── home.html

│

├── static/

│   ├── style.css

│   └── app.js

│

└── pyproject.toml

Complete Example

from py_flexo.app import PyFlexoApp
from py_flexo.middleware import Middleware

app = PyFlexoApp()


@app.route("/")
def index(request, response):
    response.text = "Welcome to PyFlexo"


@app.route("/hello/{name}")
def hello(request, response, name):
    response.text = f"Hello {name}"


@app.route("/books")
class Book:

    def get(self, request, response):
        response.text = "Book List"


@app.route("/home")
def home(request, response):
    response.html = app.template(
        "home.html",
        context={
            "title": "PyFlexo",
            "header": "Welcome"
        }
    )


@app.route("/api")
def api(request, response):
    response.json = {
        "message": "Hello JSON"
    }


class LoggingMiddleware(Middleware):

    def process_request(self, request):
        print(request.path)

    def process_response(self, response):
        print(response.status_code)


app.add_middleware(LoggingMiddleware)

Roadmap

  • Cookies
  • Sessions
  • Authentication
  • Blueprint support
  • Request validation
  • CLI
  • Dependency Injection
  • OpenAPI
  • ASGI support
  • WebSocket support

Contributing

Contributions are welcome.

Please open an issue before submitting large changes.


Author

PyFlexo is an open-source project created for developers who enjoy building fast and elegant Python web applications.

Project details


Download files

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

Source Distribution

py_flexo-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

py_flexo-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file py_flexo-0.1.0.tar.gz.

File metadata

  • Download URL: py_flexo-0.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for py_flexo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 26c736e981c00b50e67657d32b6265a29e7fc7e99ff50d62157ab8aabfc2c5e8
MD5 3a8e98cf7fd13fe9391cb71dd49b9e05
BLAKE2b-256 b37f99ae512ab4b45b21b3d95d433122ae73e8709cde03770005a826e8db6a9d

See more details on using hashes here.

File details

Details for the file py_flexo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_flexo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for py_flexo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4fb5080a790a913ec2f70f8cb76960ebca8f3a9669dff2495ad6cff2351688e3
MD5 cf880bdaf42354ae599da52621783360
BLAKE2b-256 854c8f809dce37857ca5bfff47de236191132e66b0905bbc94b3af9be9fb35e7

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