Skip to main content

Simple wrapper around gevent's wsgi server.Adds simple regex routing, error handling, and json/jsonp handling.

Project description

gserver 0.1.10

Simple wrapper around gevent that provides a basic routing engine and JSON/JSONP handling.

Here’s a simple usage example:

from gevent.monkey import patch_all; patch_all()
from gevent import queue

from gserver.routes import Routes
from gserver.request import parse_vals
from gserver.wsgi import WSGIServer

routes = Routes()
route = routes.route
route_json = routes.route_json

@route("^/example/$")
def example(req):
        return "hello"

@route("^/poll/$")
def poll(request):
        yield ' ' * 1000
        yield "hello"
        sleep(5)
        yield "goodbye" # connection is closed at this point

@route("^/queue/$")
def q(request):
        def process(b):
                b.put("<div>1</div>")
                sleep(1)
                b.put("<div>2</div>")
                sleep(1)
                b.put("<div>3</div>")

        body = queue.Queue()
        body.put(' ' * 1000)
        body.put("<!doctype html><html><head><title>hola</title><head><body>\n")
        gevent.spawn(process, body)
        return body

@route_json("^/example/(?P<name>\w+)/$", method="GET,POST")
def example_name(request, name=None):
        data = request.query_data
        if request.method == "POST":
            data = request.form_data
        query_age, query_height = parse_vals(data, "age", "height")

        return { "name": name,
                         "age": query_age,
                         "height": query_height }

if __name__ == "__main__":
        server = WSGIServer(('', 9191), routes, log=None)
        server.serve_forever()

get gserver

Install gevent, and it’s dependencies greenlet and libevent:

sudo easy_install gserver

Download the latest release from Python Package Index or clone the repository

More documentation is on it’s way (check the site for updates)

Provide any feedback and issues on the bug tracker, that should be coming soon.

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

gserver-0.1.10.tar.gz (15.6 kB view details)

Uploaded Source

File details

Details for the file gserver-0.1.10.tar.gz.

File metadata

  • Download URL: gserver-0.1.10.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for gserver-0.1.10.tar.gz
Algorithm Hash digest
SHA256 e4b50d58f7d81213595e2680f79460bd6b1ec50f08df09e31bf5b2c2a5e0fe8c
MD5 19dc02134034ec6841bbc50f29339ba6
BLAKE2b-256 3c223f47670a2c5a1177c8d15cea7c2b8a7a29b4a8054fd68c50af683512eed7

See more details on using hashes here.

Supported by

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