/grin_wsgi

My WSGI framework implementation.

Primary LanguagePythonMIT LicenseMIT

Grin WSGI

Build Status Coverage by codecov.io Maintainability

My WSGI Interface implementation

Requirements

  • Python 3.6

Installation

$ make

Usage

To run built-in test framework app type:

$ gwsgi

To run your own application you have two options:

  • Provide config.ini filepath
$ gwsgi --ini /config.ini
  • Or provide directory and module variables
$ gwsgi --chdir /opt/project --module project_name.app

For more information type: $ gwsgi -h

Test built-in framework by such requests:

Config example

[gwsgi]
chdir = /opt/project
module = project_name.app
host = localhost
port = 8051
threading = false
processing = false
wsgiref = false

A Minimal Application

from grin_wsgi.framework.http import HttpResponse
from grin_wsgi.framework.app import Project


project = Project()
app = project.register_app(__name__)


@app.route(r'hello/(.+)$', required_methods=['GET'])
@app.route(r'hello/<str:name>/page<int:page>$', required_methods=['GET'])
def hello(request, **kwargs):
    name = kwargs.get('name', request.data.get('name', 'Anonymus'))
    page = kwargs.get('page')
    html = f'Hello, {name}!'
    if page is not None:
        html += f' You are on the {page} page.'
    return HttpResponse(html)

Note: you should always create project = Project() variable to define your project. Each new Application should be registered through the project var.

Testing

$ PYTHONPATH=. pytest