Skip to main content

This is simple python web framework which written for learning purposes

Project description

Purpose Status

pyframex7

Pyframex7 is a custom Python web framework created for learning purposes.

Features

  • Minimal and easy to understand
  • Custom middleware support
  • Simple request/response handling
  • Supports both class-based and function-based handlers
  • Designed for educational use

Installation

pyframex7 is available on PyPI and can be installed with:

pip install pyframex7

Simple Use Cases

1. Function-Based Handler Example

from pyframe.app import PyFramework
from pyframe.response import Response

app = PyFramework()

# Function-based route handler
@app.router("/hello/{name}")
def hello(request, response, name):
    # Set plain text response
    response.text = f"Hello, {name}!"

# To run: Use a WSGI server like gunicorn 
# Example: gunicorn main:app

2. Class-Based Handler Example

from pyframe.app import PyFramework

app = PyFramework()

# Class-based handler for /greet/
@app.router("/greet/")
class Greet:
    def get(self, request, response):
        response.text = "Greetings from a class-based handler!"

    def post(self, request, response):
        # You can access POST data from request.params
        name = request.params.get("name", "Anonymous")
        response.text = f"Posted by {name}"

3. Using Middleware

from pyframe.middleware import Middleware

class LoggingMiddleware(Middleware):
    def process_request(self, request):
        print(f"Request path: {request.path}")

    def process_response(self, request, response):
        print(f"Response status: {response.status_code}")

# Add middleware to the app
app.add_middleware(LoggingMiddleware)

4. Simple ORM Model and Usage

from pyframe.orm import Table, Column, Database

# Define a User model/table
class User(Table):
    id = Column(int)
    name = Column(str)
    age = Column(int)

# Create a database instance (in-memory for demo)
db = Database(":memory:")

# Register the model and create the table
db.create(User)

# Now the User model is bound to the database

# Create and save multiple users
user1 = User(id=1, name="Alice", age=30)
user2 = User(id=2, name="Bob", age=25)
user3 = User(id=3, name="Charlie", age=35)
user1.save()
user2.save()
user3.save()


# Fetch all users (using Manager)
users = User.objects.all()
print("All users:", users)

# Get a single user by field (raises if not found or multiple found)
try:
    alice = User.objects.get(name="Alice")
    print("Get Alice:", alice)
except Exception as e:
    print(e)

# Filter users by age
filtered = User.objects.filter(age=25).all()
print("Users with age=25:", filtered)

# Delete a user by id
User.objects.delete(id=2)
print("After deleting Bob:", User.objects.all())

# Drop the table (removes all data and table)
db.drop(User)

Comments

  • The framework supports both function-based and class-based route handlers.
  • Middleware can be added for logging, authentication, etc.
  • The ORM allows you to define models as Python classes and map them to SQL tables.
  • Each model gets an objects attribute (a Manager) for querying, filtering, and deleting records in a Pythonic way (e.g., User.objects.all(), User.objects.get(...), User.objects.filter(...)).
  • You must bind a database connection to your model before saving data.
  • Table creation and data insertion are handled via class methods and instance methods.

Use Cases

  • Learning how web frameworks work
  • Experimenting with middleware and routing
  • Building simple web applications for educational purposes

License

This project is for learning and educational purposes only.

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

pyframex7-0.2.1.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

pyframex7-0.2.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file pyframex7-0.2.1.tar.gz.

File metadata

  • Download URL: pyframex7-0.2.1.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for pyframex7-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9fe47e0d73e30f843fae896b5cc9ea276778d4ff014a3a4815b816901ed44ac8
MD5 9fa57b12176801761dc7bea6ed898963
BLAKE2b-256 03c3c367ab0e246c90e7b305acc7bb4729b8e5a73d20ee28de8bad7c615e40e7

See more details on using hashes here.

File details

Details for the file pyframex7-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pyframex7-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for pyframex7-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2ff65b34ff8147ce4d818bb6812b24618c600e4c8ed9fe3dd2ffd13d22639e65
MD5 8c85ba3df98dd7c5f2e1c4a1629b13b8
BLAKE2b-256 ba392d7d075f2e641ed256dd3a8d249b4e724b1ca3ca1c191eca66a5ba356fa4

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