Skip to main content

A simple Python WSGI framework built for learning purposes

Project description

Oberoon: Python Web Framework

Oberoon framework logo

purpose

PyPI - Version

Oberoon is a WSGI framework for Python, written for mainly learning purposes. Can be used with any WSGI server such as Gunicorn.

Soon, the author is planning to release his own WSGI server - Obicorn, then you can easily integrate the framework with it.

Source code: https://github.com/Samandar-Komilov/oberoon

Installation

  pip install oberoon

How to use it

Basic Usage

from oberoon.app import Oberoon


app = Oberoon()


# Simple text response handlers
@app.route("/home", allowed_methods=["get"])
def home(request, response):
    response.text = "Hello from the Home Page"


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


# Class-based handlers
@app.route("/books")
class Books:
    def get(self, request, response):
        response.text = "Books page"
    
    def post(self, request, response):
        response.text = "Endpoint to create a book\n"


# Explicit addition of handlers
def new_handler(request, response):
    response.text = "From new handler"

app.add_route("/new-handler", new_handler)


# Templates support
@app.route("/template")
def template(req, resp):
    resp.body = app.template(
        "home.html",
        context = {"new_title": "Best Title", "new_body": "Best Body"}
    ).encode()


# JSON response handlers
@app.route("/json")
def json_handler(request, response):
    response_data = {"name": "some name", "type": "json"}
    response.json = response_data

Unit Tests

The recommended way of writing unit tests is with pytest. Here is an example:

def test_basic_route_adding(app):
    @app.route('/home')
    def home(req, resp):
        resp.text = "Hello from Home"


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

    assert test_client.get("http://testserver/hello/Sam").text == "Hello Sam"


def test_class_based_get(app, test_client):
    @app.route("/books")
    class Books:
        def get(self, request, response):
            response.text = "Books page"

    response = test_client.get("http://testserver/books")
    assert response.text == "Books page"
    assert response.status_code == 200

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

oberoon-0.1.3.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

oberoon-0.1.3-py2.py3-none-any.whl (6.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file oberoon-0.1.3.tar.gz.

File metadata

  • Download URL: oberoon-0.1.3.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for oberoon-0.1.3.tar.gz
Algorithm Hash digest
SHA256 69267f91f7d3c7c91b6c39ef5e9f84e72ae68f31ca74fc3aaca6e67aa14c71fd
MD5 3a0c39b16eb7f158a57735d0f174b25f
BLAKE2b-256 249891b4624d200895186dcaf5bec1a70bfb949142903164d35977029de4b024

See more details on using hashes here.

File details

Details for the file oberoon-0.1.3-py2.py3-none-any.whl.

File metadata

  • Download URL: oberoon-0.1.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for oberoon-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 abc208c6846efbb4cc42fdc421dadf1eca0a0a28b6d00c6ddd3886cb68ff78ac
MD5 934596033015d7a636f33ca5b875c30c
BLAKE2b-256 1ee96f0317b87bb71e8d0c24de6b4080e7e8021a65a250c3563fb5a7fa259655

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page