https://github.com/dbr/pyerweb
An absurdly small web-framework in Python [Not actively maintained]
https://github.com/dbr/pyerweb
Last synced: about 1 year ago
JSON representation
An absurdly small web-framework in Python [Not actively maintained]
- Host: GitHub
- URL: https://github.com/dbr/pyerweb
- Owner: dbr
- Created: 2008-11-13T11:08:53.000Z (over 17 years ago)
- Default Branch: master
- Last Pushed: 2009-04-26T17:43:24.000Z (about 17 years ago)
- Last Synced: 2025-04-08T17:21:25.708Z (about 1 year ago)
- Language: Python
- Homepage:
- Size: 89.8 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
pyerweb: an absurdly small Python web-framework
Currently pyerweb is basically a simple routing system, which allows you to do the following:
from pyerweb import GET, runner
@GET("^/view/(.+?)")
def view(key):
return "Viewing %s" % (key)
This maps /view/anything to calling view() with an argument of "anything"
You simply decorate a function with `@GET`, `@PUT` `@POST` or `@DELETE`, the argument is a regular expression (in a string), for example:
@POST("^/0-9+$")
..will match a POST request to `/1` or `/44532`
Groups in the regular expression will be passed to the decorated function as arguments, for example:
@POST("^/(0-9)+$")
def view(the_number):
pass
..will grab the supplied number as `the_number` argument
The `runner` function is the WSGI compatible runner. For example, using "spawning" you can simply run:
spawn myscript.runner
Or, to use pyerweb as a CGI script (also works for the Google App Engine):
import wsgiref.handlers
from pyerweb import GET, runner
@GET("^/view/(.+?)")
def view(key):
return "Viewing %s" % (key)
if __name__ == "__main__":
wsgiref.handlers.CGIHandler().run(runner)