Gefr: WSGI on Jython

_images/logo10.png

Gefr is a suite of adapters enables you to run Python WSGI web applications on Jython platform.

Installation

It’s always better to install gefr inside a virtual environment:

$ virtualenv -p /usr/local/bin/jython gefr-env
$ cd gefr-env
$ source bin/activate

Install jip to resolve Java dependencies:

$ pip install jip

Install gefr with pip:

$ pip install gefr

jip will download Java dependencies automatically for you. Then you are ready to use gefr.

Quick Start

You can run any WSGI application with gefr:

from gefr.core import Gefr
from gefr.backends.jetty import JettyBackend

HOST = '0.0.0.0'
PORT = 8000

def wsgiapp(environ, start_response):
    status = '200 OK'
    res_body = "<html><head><title>Welcome</title></head><body><h1>It works!</h1></body></html>"
    res_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(res_body)))]
    start_response(status, res_headers)
    return [res_body]

Gefr(wsgiapp, JettyBackend, host='0.0.0.0', port=8000).start()

To run it with libraries included, use jython-all instead of jython:

$ jython-all example.py

Backends

Gefr is design to support multiple backends. Currently, the following backends are available to use:

  • Soldat (gefr.backends.soldat.SoldatBackend)
  • Mina (gefr.backends.mina.MinaBackend)
  • Jetty (gefr.backends.jetty.JettyBackend) (Recommend)
  • Netty (gefr.backends.netty.NettyBackend)

License

Currently gefr is available according to the MIT License

Copyright (c) 2011, Sun Ning.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Project Versions

Table Of Contents

This Page