Metadata-Version: 2.4
Name: py-flexo
Version: 0.1.0
Summary: Python Web Framework built for learning purposes
Requires-Python: >=3.12
Description-Content-Type: text/markdown
Requires-Dist: gunicorn>=26.0.0
Requires-Dist: jinja2>=3.1.6
Requires-Dist: parse>=1.22.1
Requires-Dist: requests-wsgi-adapter>=0.4.1
Requires-Dist: webob>=1.8.10
Requires-Dist: whitenoise>=6.12.0

# PyFlexo

<p align="center">
A modern, lightweight and extensible WSGI web framework for Python.
</p>

<p align="center">

![Python](https://img.shields.io/badge/python-3.10%2B-blue)
![License](https://img.shields.io/badge/license-MIT-green)
![Tests](https://img.shields.io/badge/tests-passing-success)
![Version](https://img.shields.io/badge/version-0.1.0-orange)

</p>

---

## 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

```bash
pip install py_flexo
```

Using uv

```bash
uv add py_flexo
```

---

# Quick Start
main.py
```python
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:

```bash
gunicorn main:app
```

---

# Routing

## Function Based View

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

---

## Route Parameters

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

Example

```
GET /hello/Alice
```

Response

```
Hello Alice
```

---

## Class Based Views

```python
@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

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

Template

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

<body>

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

</body>
</html>
```

---

# JSON Responses

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

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

Output

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

---

# Middleware

```python
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

```python
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

```python
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.
