This is simple python web framework which written for learning purposes
Project description
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 or waitress
# 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
users = User.all()
print("All users:", users)
# Get a single user by field (raises if not found or multiple found)
try:
alice = User.get(name="Alice")
print("Get Alice:", alice)
except Exception as e:
print(e)
# Filter users by age
filtered = User.filter(age=25)
print("Users with age=25:", filtered)
# Delete a user by id
User.delete(id=2)
print("After deleting Bob:", User.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.
- 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.0.tar.gz
(9.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyframex7-0.2.0.tar.gz.
File metadata
- Download URL: pyframex7-0.2.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d329196e84f59965df05312142ce22fff81def3c3d8848a1b7d13640ab182a75
|
|
| MD5 |
4b2c696524b2008f58c5b658642a7ea4
|
|
| BLAKE2b-256 |
d01e769470de9ca5f0ace5a50f50a607a4d6b395e573f6d9d85d9815f4d21b4e
|
File details
Details for the file pyframex7-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pyframex7-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f5b9b593b70ae2e1a1a5965061fa6f84e5de41bdaeb907e2996612f79df62c0
|
|
| MD5 |
96a19899635ed6fd3f32fe86ae6e7dff
|
|
| BLAKE2b-256 |
e5ffe21a3b8c49e46d9fcbf4a8993499d2a7f108b93f19a176b5de8f7d70d377
|