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.2

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

Here’s a simple usage example:

import gevent
from gevent import queue
from gserver import Routes
from gserver.wsgi import WSGIServer, parse_vals

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

@route("^/example/$")
def example(env, resp):
        return "hello"

@route("^/poll/$")
def poll(env, resp):
        yield ' ' * 1000
        yield "hello"
        sleep(5)        # requires either gevent.sleep or time.sleep with monkey patching
        yield "goodbye" # connection is closed at this point

@route("^/queue/$"):
def queue(env, resp):
        def process(b):
                b.put("hello")
                sleep(5)
                b.put("goodbye") # does not close the connection

        body = queue.Queue()
        body.put(' ' * 1000)
        gevent.spawn(process, body)
        return body

@route_json("^/example/(?P<name>\w+)/$", method="GET,POST")
def example_name(env, resp, name=None):
        query_age, query_height = parse_vals(env, "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.2.tar.gz (8.5 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for gserver-0.1.2.tar.gz
Algorithm Hash digest
SHA256 98239a99b886092a0645310d8c25f77571d25b8f2a90edfab4075314d22f1bdc
MD5 0f9ea0992b1386750a5d7d791760f03e
BLAKE2b-256 2a954a65b84b541a96c9665ab59e4b29c1c9d8a4eaf61bc47c6c2905a17dc716

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